Class LiterallySignedStringMap
- java.lang.Object
-
- it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction<CharSequence>
-
- it.unimi.dsi.util.LiterallySignedStringMap
-
- All Implemented Interfaces:
Function<CharSequence,Long>,Object2LongFunction<CharSequence>,StringMap<MutableString>,Serializable,Function<CharSequence,Long>,ToLongFunction<CharSequence>
public class LiterallySignedStringMap extends AbstractObject2LongFunction<CharSequence> implements StringMap<MutableString>, Serializable
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 fullStringMapimplementation.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 ofCharSequenceyou 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.A typical usage of this class pairs a
FrontCodedStringListwith some kind of succinct structure from Sux4J.- Since:
- 1.0.8
- Author:
- Sebastiano Vigna
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Object2LongFunction<? extends CharSequence>functionThe underlying map.protected ObjectList<? extends MutableString>listThe underlying list.protected intsizeThe size oflist.-
Fields inherited from class it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction
defRetValue
-
-
Constructor Summary
Constructors Constructor Description LiterallySignedStringMap(Object2LongFunction<? extends CharSequence> function, ObjectList<? extends MutableString> list)Creates a new shift-add-xor signed string map using a given hash map.
-
Method Summary
Modifier and Type Method Description booleancontainsKey(Object o)Longget(Object o)Deprecated.longgetLong(Object o)ObjectList<? extends MutableString>list()Returns a list view of the domain of this string map (optional operation).static voidmain(String[] arg)intsize()-
Methods inherited from class it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction
defaultReturnValue, defaultReturnValue
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface it.unimi.dsi.fastutil.objects.Object2LongFunction
applyAsLong, defaultReturnValue, defaultReturnValue, put, put, remove, removeLong
-
-
-
-
Field Detail
-
function
protected final Object2LongFunction<? extends CharSequence> function
The underlying map.
-
list
protected final ObjectList<? extends MutableString> list
The underlying list.
-
size
protected final int size
The size oflist.
-
-
Constructor Detail
-
LiterallySignedStringMap
public LiterallySignedStringMap(Object2LongFunction<? extends CharSequence> function, ObjectList<? extends MutableString> list)
Creates a new shift-add-xor signed string map using a given hash map.- Parameters:
function- a function mapping each string inlistto its ordinal position.list- a list of strings.
-
-
Method Detail
-
getLong
public long getLong(Object o)
- Specified by:
getLongin interfaceObject2LongFunction<CharSequence>
-
get
@Deprecated public Long get(Object o)
Deprecated.- Specified by:
getin interfaceFunction<CharSequence,Long>- Specified by:
getin interfaceObject2LongFunction<CharSequence>
-
size
public int size()
- Specified by:
sizein interfaceFunction<CharSequence,Long>
-
containsKey
public boolean containsKey(Object o)
- Specified by:
containsKeyin interfaceFunction<CharSequence,Long>
-
list
public ObjectList<? extends MutableString> list()
Description copied from interface:StringMapReturns a list view of the domain of this string map (optional operation).Note that the list view acts as an inverse of the mapping implemented by this map.
- Specified by:
listin interfaceStringMap<MutableString>- Returns:
- a list view of the domain of this string map, or
nullif this map does not support this operation.
-
main
public static void main(String[] arg) throws IOException, JSAPException, ClassNotFoundException, SecurityException, NoSuchMethodException
-
-