Package org.apache.hadoop.util
Class IdentityHashStore<K,V>
java.lang.Object
org.apache.hadoop.util.IdentityHashStore<K,V>
- Type Parameters:
K- The key type to use.V- THe value type to use.
The IdentityHashStore stores (key, value) mappings in an array.
It is similar to java.util.HashTable, but much more lightweight.
Neither inserting nor removing an element ever leads to any garbage
getting created (assuming the array doesn't need to be enlarged).
Unlike HashTable, it compares keys using
System.identityHashCode(Object) and the identity operator.
This is useful for types like ByteBuffer which have expensive hashCode
and equals operators.
We use linear probing to resolve collisions. This avoids the need for
the overhead of linked list data structures. It also means that it is
expensive to attempt to remove an element that isn't there, since we
have to look at the entire array to be sure that it doesn't exist.-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcapacity()Retrieve a value associated with a given key.booleanisEmpty()intvoidAdd a new (key, value) mapping.Retrieve a value associated with a given key, and delete the relevant entry.voidvisitAll(IdentityHashStore.Visitor<K, V> visitor) Visit all key, value pairs in the IdentityHashStore.
-
Constructor Details
-
IdentityHashStore
public IdentityHashStore(int capacity)
-
-
Method Details
-
put
Add a new (key, value) mapping. Inserting a new (key, value) never overwrites a previous one. In other words, you can insert the same key multiple times and it will lead to multiple entries.- Parameters:
k- Generics Type k.v- Generics Type v.
-
get
Retrieve a value associated with a given key.- Parameters:
k- Generics Type k.- Returns:
- Generics Type V.
-
remove
Retrieve a value associated with a given key, and delete the relevant entry.- Parameters:
k- Generics Type k.- Returns:
- Generics Type V.
-
isEmpty
public boolean isEmpty() -
numElements
public int numElements() -
capacity
public int capacity() -
visitAll
Visit all key, value pairs in the IdentityHashStore.- Parameters:
visitor- visitor.
-