public final class FrozenHashKeyIndex extends Object implements KeyIndex, Serializable
Immutable key index backed by a hash table.
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(long id)
Query whether this index contains a particular key.
|
static FrozenHashKeyIndex |
create(LongCollection keys)
Create a new key index.
|
static FrozenHashKeyIndex |
create(LongList keys)
Construct a new key index.
|
FrozenHashKeyIndex |
frozenCopy()
Get a frozen copy of this key index.
|
int |
getIndex(long id)
Get the index of a key.
|
long |
getKey(int idx)
Get the key for an index position.
|
LongList |
getKeyList()
Get the list of indexed keys.
|
int |
getLowerBound()
Get the lower bound of the index range for this index.
|
int |
getUpperBound()
Get the upper bound of the index range for this index.
|
int |
size()
Get the size of this index.
|
int |
tryGetIndex(long id)
Try to get the index for an ID, returning a negative value if it does not exist.
|
public static FrozenHashKeyIndex create(LongList keys)
Construct a new key index. It maps each long key to its position in the list.
keys
- The list of keys to store.public static FrozenHashKeyIndex create(LongCollection keys)
Create a new key index.
keys
- The keys.keys
.public int getIndex(long id)
KeyIndex
Get the index of a key.
public boolean containsKey(long id)
KeyIndex
Query whether this index contains a particular key.
containsKey
in interface KeyIndex
id
- The key to look for.true
if the index contains the key.public long getKey(int idx)
KeyIndex
Get the key for an index position.
public LongList getKeyList()
KeyIndex
Get the list of indexed keys. This list is 0-indexed, so the key at position 0 in this list is at index KeyIndex.getLowerBound()
in the key index.
getKeyList
in interface KeyIndex
public int tryGetIndex(long id)
KeyIndex
Try to get the index for an ID, returning a negative value if it does not exist. This method is like KeyIndex.getIndex(long)
, except it returns a negative value instead of throwing an exception if the id does not exist.
tryGetIndex
in interface KeyIndex
id
- The ID to look for.public int size()
KeyIndex
Get the size of this index.
public int getLowerBound()
KeyIndex
Get the lower bound of the index range for this index.
getLowerBound
in interface KeyIndex
public int getUpperBound()
KeyIndex
Get the upper bound of the index range for this index.
getUpperBound
in interface KeyIndex
public FrozenHashKeyIndex frozenCopy()
KeyIndex
Get a frozen copy of this key index. If the key index is mutable, then this method will return an immutable copy of it. If the key index is already immutable, it may just return itself without copying.
frozenCopy
in interface KeyIndex