java.lang.Object
org.elasticsearch.common.util.LongLongHash
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.lucene.util.Accountable,LongLongHashTable,Releasable
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.-
Field Summary
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE -
Constructor Summary
ConstructorsConstructorDescriptionLongLongHash(long capacity, float maxLoadFactor, BigArrays bigArrays) LongLongHash(long capacity, BigArrays bigArrays) -
Method Summary
Modifier and TypeMethodDescriptionlongadd(long key1, long key2) Try to addkey.longcapacity()Return the number of allocated slots to store this hash table.voidclose()longfind(long key1, long key2) Get the id associated withkeyor -1 if the key is not contained in the hash.protected final longgetAndSetId(long index, long id) Set the id provided key at0 <= index <= capacity()and get the previous value or -1 if this slot is unused.longgetKey1(long id) Return the first key at0 <= index <= capacity().longgetKey2(long id) Return the second key at0 <= index <= capacity().protected final voidgrow()longid(long index) Get the id associated with key at0 <= index <= capacity()or -1 if this slot is unused.longprotected voidremoveAndAdd(long index) Remove the entry at the given index and add it backprotected voidresize(long capacity) Resize to the given capacity.protected final voidsetId(long index, long id) Set the id provided key at0 <= index <= capacity().longsize()Return the number of longs in this hash table.protected booleanused(long bucket) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResourcesMethods inherited from interface org.elasticsearch.common.util.LongLongHashTable
size
-
Constructor Details
-
LongLongHash
-
LongLongHash
-
-
Method Details
-
getKey1
public long getKey1(long id) Return the first key at0 <= index <= capacity(). The result is undefined if the slot is unused.- Specified by:
getKey1in interfaceLongLongHashTable
-
getKey2
public long getKey2(long id) Return the second key at0 <= index <= capacity(). The result is undefined if the slot is unused.- Specified by:
getKey2in interfaceLongLongHashTable
-
find
public long find(long key1, long key2) Get the id associated withkeyor -1 if the key is not contained in the hash.- Specified by:
findin interfaceLongLongHashTable
-
add
public long add(long key1, long key2) Try to addkey. Return its newly allocated id if it wasn't in the hash table yet, or-1-idif it was already present in the hash table.- Specified by:
addin interfaceLongLongHashTable
-
removeAndAdd
protected void removeAndAdd(long index) Remove the entry at the given index and add it back -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceReleasable
-
ramBytesUsed
public long ramBytesUsed()- Specified by:
ramBytesUsedin interfaceorg.apache.lucene.util.Accountable
-
id
public long id(long index) Get the id associated with key at0 <= index <= capacity()or -1 if this slot is unused. -
setId
protected final void setId(long index, long id) Set the id provided key at0 <= index <= capacity(). -
getAndSetId
protected final long getAndSetId(long index, long id) Set the id provided key at0 <= index <= capacity()and get the previous value or -1 if this slot is unused. -
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()
-