Create new RefList and RefMap utility types
commitab697ff18b09e5d49e028b7a32844d408b02ccf2
authorShawn O. Pearce <spearce@spearce.org>
Sat, 23 Jan 2010 00:27:03 +0000 (22 16:27 -0800)
committerShawn O. Pearce <spearce@spearce.org>
Sat, 23 Jan 2010 00:27:30 +0000 (22 16:27 -0800)
tree089a4b6404bf506e870b14cb5c06d6d91407478f
parentf5eb0d93660786213b98dadde7d93c5605454495
Create new RefList and RefMap utility types

These types can be used by RefDatabase implementations to manage
the collection.

A RefList stores items sorted by their name, and is an immutable
type using copy-on-write semantics to perform modifications to
the collection.  Binary search is used to locate an existing item
by name, or to locate the proper insertion position if an item does
not exist.

A RefMap can merge up to 3 RefList collections at once during its
entry iteration, allowing items in the resolved or loose RefList
to override items by the same name in the packed RefList.

The RefMap's goal is O(log N) lookup time, and O(N) iteration time,
which is suitable for returning from a RefDatabase.  By relying on
the immutable RefList we might be able to make map construction
nearly constant, making Repository.getAllRefs() an inexpensive
operation if the caches are current.  Since modification is not
common, changes require up to O(N + log N) time to copy the internal
list and collapse or expand the list's array.  As most changes
are made to the loose collection and not the packed collection,
in practice most changes would require less than the full O(N)
time, due to a significantly smaller N in the loose list.

Almost complete test coverage is included in the corresponding
unit tests.  A handful of methods on RefMap are not tested in this
change, as writing the proper test depends on a future refactoring
of how the Ref class represents symbolic reference names.

Change-Id: Ic2095274000336556f719edd75a5c5dd6dd1d857
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefListTest.java [new file with mode: 0644]
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefMapTest.java [new file with mode: 0644]
org.eclipse.jgit/src/org/eclipse/jgit/lib/RefComparator.java
org.eclipse.jgit/src/org/eclipse/jgit/util/RefList.java [new file with mode: 0644]
org.eclipse.jgit/src/org/eclipse/jgit/util/RefMap.java [new file with mode: 0644]