java.lang.Object
org.elasticsearch.common.util.Int3Hash
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Releasable
Specialized hash table implementation similar to BytesRefHash that maps
three 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 3 for faster identification of buckets.
This class is not thread-safe.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlong
add
(int key1, int key2, int key3) Try to addkey
.long
capacity()
Return the number of allocated slots to store this hash table.void
close()
long
find
(int key1, int key2, int key3) Get the id associated withkey
or -1 if the key is not contained in the hash.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.int
getKey1
(long id) int
getKey2
(long id) int
getKey3
(long id) protected final void
grow()
long
id
(long index) Get the id associated with key at0 <= index <= capacity()
or -1 if this slot is unused.protected void
removeAndAdd
(long index) Remove the entry at the given index and add it backprotected void
resize
(long capacity) Resize to the given capacity.protected final void
setId
(long index, long id) Set the id provided key at0 <= index <= capacity()
.long
size()
Return the number of longs in this hash table.protected boolean
used
(long bucket)
-
Constructor Details
-
Int3Hash
-
Int3Hash
-
-
Method Details
-
getKey1
public int getKey1(long id) -
getKey2
public int getKey2(long id) -
getKey3
public int getKey3(long id) -
find
public long find(int key1, int key2, int key3) Get the id associated withkey
or -1 if the key is not contained in the hash. -
add
public long add(int key1, int key2, int key3) Try to addkey
. 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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in 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()
-