|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.metastatic.rsync.TwoKeyMap
This is a "double-keyed" mapping. The first key is a 16-bit integer, and the second key is a variable-length byte array. With this, we can compute if a given mapping is "probably" in the map using the first key, and compute whether or not a mapping is definitely in the hashtable with the second key. The rationale behind this is that the first key is trivial to compute and that the second key is more difficult to compute but more unique.
Since the strong key can be a byte array of any length, then this "strong" key can be shorter (and thus less unique) than the "weak" key. For this class to work properly, the stronger key should be at least four bytes in length, preferably longer.
The weak-key/strong-key method is inspired by (and is was written for) the "hashtable" in the rsync algorithm, and has three levels of key search:
MessageDigest
, and thus takes longer to compute.With this method, we can determine if it is worth it to compute the strong key if we have already computed the weak key.
null
is not a valid key in this map.
Nested Class Summary | |
---|---|
class |
TwoKeyMap.StrongKey
The stronger of the two keys in this Map . |
class |
TwoKeyMap.SubTable
A Map.Entry that contains another Map that is keyed with stronger, larger keys, and links
to other SubTables whose TwoKeyMap.SubTable.key 's lower four bytes are
equivalent. |
Field Summary | |
---|---|
protected TwoKeyMap.SubTable[] |
tables
The sub-tables whose keys are the larger, stronger keys. |
Constructor Summary | |
---|---|
TwoKeyMap()
Creates a new Map with 2^16 sub-tables. |
|
TwoKeyMap(Map m)
Create a new Map with all the mappings of the given map. |
Method Summary | |
---|---|
void |
clear()
Clear this Map. |
boolean |
containsKey(int key)
Test if the map contains the lower two bytes of the weak key. |
boolean |
containsKey(Object key)
Test if this map contains either the supplied weak key (if the argument is an Integer) or both the weak and strong keys (if the argument is a ChecksumPair ). |
boolean |
containsValue(Object value)
Test if the given value is in one of the sub-tables. |
Set |
entrySet()
Return an unmodifiable set of the SubTable objects in this class. |
boolean |
equals(Object o)
Test if this object equals another. |
Object |
get(Object key)
Get the object mapped to by the given key pair. |
int |
hashCode()
Return the hash code of this object. |
boolean |
isEmpty()
Test if there are no mappings in this map. |
Set |
keySet()
Return an unmodifiable set of all the pairs of keys in this mapping. |
Object |
put(Object key,
Object value)
Put the given object at the location specified by a key pair. |
void |
putAll(Map m)
Put every entry in m in this map. |
Object |
remove(Object key)
Removes a single mapping if the argument is a ChecksumPair , or
an entire TwoKeyMap.SubTable if the argument is a Integer . |
int |
size()
Return the number of mappings. |
String |
toString()
Create a printable version of this Map. |
Collection |
values()
Return a Collection of all the values mapped by this object. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
protected final TwoKeyMap.SubTable[] tables
Constructor Detail |
public TwoKeyMap()
public TwoKeyMap(Map m)
m
- The initial mappings this Map should contain.
ClassCastException
- If one of the keys in
m
is not a ChecksumPair.
NullPointerException
- If one of the keys in
m
is null.Method Detail |
public boolean containsKey(int key)
containsKey
method.
key
- The key to check.
key & 0xffff
in tables
is non-null.public Object put(Object key, Object value)
put
in interface Map
key
- The ChecksumPair
to use as the key.value
- The value to map to.
public boolean containsKey(Object key)
ChecksumPair
).
containsKey
in interface Map
key
- The key to check.
key
is an Integer) or the given pair of keys (if
key
is a ChecksumPair
).public Object get(Object key)
ChecksumPair
.
get
in interface Map
key
- The key of the object to get.
key
, or null
if there is no such object.public void clear()
clear
in interface Map
public boolean containsValue(Object value)
containsValue
in interface Map
value
- The value to search for.
public Set entrySet()
entrySet
in interface Map
public boolean equals(Object o)
equals
in interface Map
equals
in class Object
ClassCastException
- if o is not an
instance of this class.
NullPointerException
- if o is null.public int hashCode()
hashCode
in interface Map
hashCode
in class Object
public boolean isEmpty()
isEmpty
in interface Map
public Set keySet()
keySet
in interface Map
ChecksumPair
s in this mapping.public void putAll(Map m)
m
in this map. This method will
only work if the keys of m
are of type ChecksumPair
.
putAll
in interface Map
m
- The mappings to put.
ClassCastException
- If every key in m
is not a ChecksumPair.
NullPointerException
- If a key in m
is null.put(Object,Object)
public Object remove(Object key)
ChecksumPair
, or
an entire TwoKeyMap.SubTable
if the argument is a Integer
.
remove
in interface Map
key
- The key of the object to be removed.
null
otherwise.public int size()
size
in interface Map
public Collection values()
values
in interface Map
public String toString()
toString
in class Object
String
representing this object.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |