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.

@Private @Evolving public final class IdentityHashStore<K,V> extends Object
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.
  • Constructor Details

    • IdentityHashStore

      public IdentityHashStore(int capacity)
  • Method Details

    • put

      public void put(K k, V v)
      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

      public V get(K k)
      Retrieve a value associated with a given key.
      Parameters:
      k - Generics Type k.
      Returns:
      Generics Type V.
    • remove

      public V remove(K k)
      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

      public void visitAll(IdentityHashStore.Visitor<K,V> visitor)
      Visit all key, value pairs in the IdentityHashStore.
      Parameters:
      visitor - visitor.