Class LongLongHash

java.lang.Object
org.elasticsearch.common.util.LongLongHash
All Implemented Interfaces:
Closeable, AutoCloseable, org.elasticsearch.core.Releasable

public final class LongLongHash extends Object
Specialized hash table implementation similar to BytesRefHash that maps two long values to ids. Collisions are resolved with open addressing and linear probing, growth is smooth thanks to BigArrays and capacity is always a multiple of 2 for faster identification of buckets. This class is not thread-safe.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LongLongHash(long capacity, float maxLoadFactor, BigArrays bigArrays)
     
    LongLongHash(long capacity, BigArrays bigArrays)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    add(long key1, long key2)
    Try to add key.
    long
    Return the number of allocated slots to store this hash table.
    void
     
    long
    find(long key1, long key2)
    Get the id associated with key or -1 if the key is not contained in the hash.
    long
    getKey1(long id)
    Return the first key at 0 <= index <= capacity().
    long
    getKey2(long id)
    Return the second key at 0 <= index <= capacity().
    protected void
     
    long
    id(long index)
    Get the id associated with key at 0 <= index <= capacity() or -1 if this slot is unused.
    protected long
    id(long index, long id)
     
    protected void
    removeAndAdd(long index)
    Remove the entry at the given index and add it back
    protected void
    resize(long capacity)
    Resize to the given capacity.
    long
    Return the number of longs in this hash table.
    protected boolean
    used(long bucket)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LongLongHash

      public LongLongHash(long capacity, BigArrays bigArrays)
    • LongLongHash

      public LongLongHash(long capacity, float maxLoadFactor, BigArrays bigArrays)
  • Method Details

    • getKey1

      public long getKey1(long id)
      Return the first key at 0 &lt;= index &lt;= capacity(). The result is undefined if the slot is unused.
    • getKey2

      public long getKey2(long id)
      Return the second key at 0 &lt;= index &lt;= capacity(). The result is undefined if the slot is unused.
    • find

      public long find(long key1, long key2)
      Get the id associated with key or -1 if the key is not contained in the hash.
    • add

      public long add(long key1, long key2)
      Try to add key. Return its newly allocated id if it wasn't in the hash table yet, or -1-id if it was already present in the hash table.
    • removeAndAdd

      protected void removeAndAdd(long index)
      Remove the entry at the given index and add it back
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface org.elasticsearch.core.Releasable
    • id

      public long id(long index)
      Get the id associated with key at 0 <= index <= capacity() or -1 if this slot is unused.
    • id

      protected final long id(long index, long id)
    • resize

      protected void resize(long capacity)
      Resize to the given capacity.
    • used

      protected boolean used(long bucket)
    • capacity

      public long capacity()
      Return the number of allocated slots to store this hash table.
    • size

      public long size()
      Return the number of longs in this hash table.
    • grow

      protected final void grow()