Package smile.hash
Class PerfectHash
java.lang.Object
smile.hash.PerfectHash
- All Implemented Interfaces:
Serializable
A perfect hash of an array of strings to their index in the array.
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
.
- See Also:
-
Constructor Summary
ConstructorDescriptionPerfectHash
(int[] select, String... keywords) Constructor.PerfectHash
(String... keywords) Constructor. -
Method Summary
-
Constructor Details
-
PerfectHash
Constructor.- Parameters:
keywords
- the fixed set of keywords.
-
PerfectHash
Constructor.- Parameters:
select
- The character positions in keywords used to calculate the hash.keywords
- the fixed set of keywords.
-
-
Method Details
-
get
Returns the index of a keyword. If the string is not in the set, returns -1.- Parameters:
key
- the keyword.- Returns:
- the index of keyword or -1.
-