Package opennlp.tools.ml.model
Class IndexHashTable<T>
- java.lang.Object
-
- opennlp.tools.ml.model.IndexHashTable<T>
-
public class IndexHashTable<T> extends java.lang.Object
TheIndexHashTable
is a hash table which maps entries of an array to their index in the array. All entries in the array must be unique otherwise a well-defined mapping is not possible.The entry objects must implement
Object.equals(Object)
andObject.hashCode()
otherwise the behavior of this class is undefined.The implementation uses a hash table with open addressing and linear probing.
The table is thread safe and can concurrently accessed by multiple threads, thread safety is achieved through immutability. Though its not strictly immutable which means, that the table must still be safely published to other threads.
-
-
Constructor Summary
Constructors Constructor Description IndexHashTable(T[] mapping, double loadfactor)
Initializes the current instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
get(T key)
Retrieves the index for the specified key.int
size()
Retrieves the size.T[]
toArray(T[] array)
-
-
-
Constructor Detail
-
IndexHashTable
public IndexHashTable(T[] mapping, double loadfactor)
Initializes the current instance. The specified array is copied into the table and later changes to the array do not affect this table in any way.- Parameters:
mapping
- the values to be indexed, all values must be unique otherwise a well-defined mapping of an entry to an index is not possibleloadfactor
- the load factor, usually 0.7- Throws:
java.lang.IllegalArgumentException
- if the entries are not unique
-
-