Class LiterallySignedStringMap

All Implemented Interfaces:
StringMap<MutableString>, Function<CharSequence,Long>, Object2LongFunction<CharSequence>, Size64, Serializable, Function<CharSequence,Long>, ToLongFunction<CharSequence>

public class LiterallySignedStringMap extends AbstractObject2LongFunction<CharSequence> implements StringMap<MutableString>, Serializable, Size64
A string map based on a function signed using the original list of strings.

A minimal perfect hash function maps a set of string to an initial segment of the natural numbers, but will actually map any string to that segment. We can check that a string is part of the key set by hashing it to a value h, and checking that the h-th string of the original list does coincide. Since, moreover, this class implements StringMap, and thus exposes the original list, we have a two-way dictionary. In other words, this is a full StringMap implementation.

Note that some care must be exercised: CharSequence's contract does not prescribe equality by content, so if your function behaves badly on some implementations of CharSequence you might make the checks fail. To avoid difficulties, the constructor checks that every string in the list is hashed correctly.

For the same reason, this class implements StringMap<MutableString>, and requires that the list of strings provided at construction time is actually a list of mutable strings.

Since:
2.0
Author:
Sebastiano Vigna
See Also: