java.lang.Object
org.elasticsearch.common.util.IntNHash
- All Implemented Interfaces:
Closeable,AutoCloseable,Releasable
Specialized hash table implementation maps N int 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 N for faster identification of buckets.
This class is not thread-safe.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongadd(int[] keys) Try to addkey.longcapacity()Return the number of allocated slots to store this hash table.voidclose()longfind(int[] keys) 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.int[]getKeys(long id) voidgetKeys(long id, int[] dst) protected final voidgrow()longid(long index) Get the id associated with key at0 <= index <= capacity()or -1 if this slot is unused.protected 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)
-
Constructor Details
-
IntNHash
-
IntNHash
-
-
Method Details
-
getKeys
public int[] getKeys(long id) -
getKeys
public void getKeys(long id, int[] dst) -
find
public long find(int[] keys) -
add
public long add(int[] keys) 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. -
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
-
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()
-