Package org.elasticsearch.common.util
Class LongHash
java.lang.Object
org.elasticsearch.common.util.LongHash
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- org.elasticsearch.core.Releasable
Specialized hash table implementation similar to BytesRefHash that maps
 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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionlongadd(long key)Try to addkey.longcapacity()Return the number of allocated slots to store this hash table.voidclose()longfind(long key)Get the id associated withkeyor -1 if the key is not contained in the hash.longget(long id)Return the key at0 <= index <= capacity().protected voidgrow()longid(long index)Get the id associated with key at0 <= index <= capacity()or -1 if this slot is unused.protected longid(long index, long id)protected voidremoveAndAdd(long index)Remove the entry at the given index and add it backprotected voidresize(long capacity)Resize to the given capacity.longsize()Return the number of longs in this hash table.protected booleanused(long bucket)
- 
Constructor Details- 
LongHash
- 
LongHash
 
- 
- 
Method Details- 
getpublic long get(long id)Return the key at0 <= index <= capacity(). The result is undefined if the slot is unused.
- 
findpublic long find(long key)Get the id associated withkeyor -1 if the key is not contained in the hash.
- 
addpublic long add(long key)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.
- 
removeAndAddprotected void removeAndAdd(long index)Remove the entry at the given index and add it back
- 
closepublic void close()- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein interface- org.elasticsearch.core.Releasable
 
- 
idpublic long id(long index)Get the id associated with key at0 <= index <= capacity()or -1 if this slot is unused.
- 
idprotected final long id(long index, long id)
- 
resizeprotected void resize(long capacity)Resize to the given capacity.
- 
usedprotected boolean used(long bucket)
- 
capacitypublic long capacity()Return the number of allocated slots to store this hash table.
- 
sizepublic long size()Return the number of longs in this hash table.
- 
growprotected final void grow()
 
-