public class IndexHashTable<T>
extends java.lang.Object
IndexHashTable
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)
and
Object.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 and Description |
---|
IndexHashTable(T[] mapping,
double loadfactor)
Initializes the current instance.
|
Modifier and Type | Method and Description |
---|---|
int |
get(T key)
Retrieves the index for the specified key.
|
int |
size()
Retrieves the size.
|
T[] |
toArray(T[] array) |
public IndexHashTable(T[] mapping, double loadfactor)
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.7java.lang.IllegalArgumentException
- if the entries are not uniqueCopyright © 2010 - 2020 Adobe. All Rights Reserved