public final class HashKeyIndex extends java.lang.Object implements KeyIndex, java.io.Serializable
Mutable index mapping backed by a hash table. This mapping allows indexes to be obtained before all keys have been seen, making it very useful for incremental processing.
Constructor and Description |
---|
HashKeyIndex()
Construct a new empty indexer.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(long id)
Query whether this index contains a particular key.
|
static HashKeyIndex |
create() |
static HashKeyIndex |
create(LongList keys)
Construct a new indexer.
|
static FrozenHashKeyIndex |
createFrozen(LongList keys)
Convenience method to create a frozen key index.
|
FrozenHashKeyIndex |
frozenCopy()
Make an immutable copy of this index mapping.
|
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 |
internId(long key)
Get an index for a key, generating a new one if necessary.
|
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 HashKeyIndex()
Construct a new empty indexer. The first interned ID will have index 0.
public static HashKeyIndex create()
public static HashKeyIndex create(LongList keys)
Construct a new indexer. It maps each long key to its position in the list, and then be ready for more keys.
keys
- The list of keys to store.public static FrozenHashKeyIndex createFrozen(LongList keys)
Convenience method to create a frozen key index.
keys
- The keys.FrozenHashKeyIndex.create(LongList)
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 int internId(long key)
Get an index for a key, generating a new one if necessary.
key
- The key.public FrozenHashKeyIndex frozenCopy()
Make an immutable copy of this index mapping.
frozenCopy
in interface KeyIndex