public class PerfectStringHash extends Object implements Hash<String>
However, the supplied array is not retained. This means that the implementation cannot necessarily confirm that a string is not in the supplied array. Where this implementation cannot distinguish that a string is not in the array, a 'valid' hash value may be returned. Under no circumstances will a hash value be returned that is greater than or equal to n.
IMPORTANT NOTE: The array of strings supplied to the constructor will be
mutated: it is re-ordered so that hash(a[i]) == i. Application code must generally
use this information to map hash values back onto the appropriate string value.
NOTE: Good performance of this algorithm is predicated on string hash values
being cached by the String class. Experience indicates that is is a good assumption.
| Constructor and Description |
|---|
PerfectStringHash(String[] values)Constructs a minimal perfect string hashing over the supplied strings. |
| Modifier and Type | Method and Description |
|---|---|
HashRange | getRange()Returns the hash range for this hash function. |
BigInteger | hashAsBigInt(String value)The hash value as a BigInteger. |
int | hashAsInt(String value)The hash value as an int. |
long | hashAsLong(String value)The hash value as a long. |
public PerfectStringHash(String[] values)
values - an array of unique non-null strings that will be reordered such that hash(values[i]) == i.public HashRange getRange()
Hashpublic BigInteger hashAsBigInt(String value)
HashBigInteger. This method may be useful in circumstances where the
generated hash is too large to be accomodated in a single primitive value, eg. if
cryptographic hashes are being used.hashAsBigInt in interface Hash<String>value - the object to be hashedpublic int hashAsInt(String value)
HashHashRange.public long hashAsLong(String value)
HashHashRange.hashAsLong in interface Hash<String>value - the object to be hashed