public class PerfectHash
extends java.lang.Object
implements java.io.Serializable
A perfect hash function for a set S is a hash function
that maps distinct elements in S to a set of integers,
with no collisions. In mathematical terms, it is an injective function.
Perfect hash functions may be used to implement a lookup table with constant worst-case access time.
A perfect hash function for a specific set S can be found by
a randomized algorithm in a number of operations that is proportional
to the size of S. The original construction of Fredman,
Komlós and Szemerédi (1984) chooses a large prime p
(larger than the size of the universe from which S is drawn),
and a parameter k, and maps each element x of
S to the index g(x) = (kx mod p) mod n.
| Constructor and Description |
|---|
PerfectHash(int[] select,
java.lang.String... keywords)
Constructs the perfect hash of strings.
|
PerfectHash(java.lang.String... keywords)
Constructs the perfect hash of strings.
|
| Modifier and Type | Method and Description |
|---|---|
int |
get(java.lang.String key)
Returns the index of a string.
|
public PerfectHash(java.lang.String... keywords)
public PerfectHash(int[] select,
java.lang.String... keywords)
select - The character positions in keywords used to calculate the hash.