Package org.elasticsearch.common.util
Class BytesRefHash
java.lang.Object
org.elasticsearch.common.util.BytesRefHash
- All Implemented Interfaces:
Closeable,AutoCloseable,org.elasticsearch.core.Releasable
Specialized hash table implementation similar to Lucene's BytesRefHash that maps
BytesRef values to ids. Collisions are resolved with open addressing and linear
probing, growth is smooth thanks to
BigArrays, hashes are cached for faster
re-hashing and capacity is always a multiple of 2 for faster identification of buckets.
This class is not thread-safe.-
Constructor Summary
ConstructorsConstructorDescriptionBytesRefHash(long capacity, float maxLoadFactor, BigArrays bigArrays)BytesRefHash(long capacity, BigArrays bigArrays) -
Method Summary
Modifier and TypeMethodDescriptionlongadd(org.apache.lucene.util.BytesRef key)Sugar toadd(key, key.hashCode().longadd(org.apache.lucene.util.BytesRef key, int code)Try to addkey.longcapacity()Return the number of allocated slots to store this hash table.voidclose()longfind(org.apache.lucene.util.BytesRef key)Sugar forfind(key, key.hashCode()longfind(org.apache.lucene.util.BytesRef key, int code)Get the id associated withkeyorg.apache.lucene.util.BytesRefget(long id, org.apache.lucene.util.BytesRef dest)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
-
BytesRefHash
-
BytesRefHash
-
-
Method Details
-
get
public org.apache.lucene.util.BytesRef get(long id, org.apache.lucene.util.BytesRef dest)Return the key at0 <= index <= capacity(). The result is undefined if the slot is unused.Beware that the content of the
BytesRefmay become invalid as soon asclose()is called -
find
public long find(org.apache.lucene.util.BytesRef key, int code)Get the id associated withkey -
find
public long find(org.apache.lucene.util.BytesRef key)Sugar forfind(key, key.hashCode() -
add
public long add(org.apache.lucene.util.BytesRef key, int code)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. -
add
public long add(org.apache.lucene.util.BytesRef key)Sugar toadd(key, key.hashCode(). -
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 interfaceorg.elasticsearch.core.Releasable
-
id
public long id(long index)Get the id associated with key at0 <= 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()
-