Class LiterallySignedStringMap

  • All Implemented Interfaces:
    StringMap<MutableString>, it.unimi.dsi.fastutil.Function<java.lang.CharSequence,​java.lang.Long>, it.unimi.dsi.fastutil.objects.Object2LongFunction<java.lang.CharSequence>, it.unimi.dsi.fastutil.Size64, java.io.Serializable, java.util.function.Function<java.lang.CharSequence,​java.lang.Long>, java.util.function.ToLongFunction<java.lang.CharSequence>

    public class LiterallySignedStringMap
    extends it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction<java.lang.CharSequence>
    implements StringMap<MutableString>, java.io.Serializable, it.unimi.dsi.fastutil.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:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected it.unimi.dsi.fastutil.objects.Object2LongFunction<? extends java.lang.CharSequence> function
      The underlying map.
      protected it.unimi.dsi.fastutil.objects.ObjectBigList<? extends MutableString> list
      The underlying list.
      protected long size
      The size of list.
      • Fields inherited from class it.unimi.dsi.fastutil.objects.AbstractObject2LongFunction

        defRetValue
    • Constructor Summary

      Constructors 
      Constructor Description
      LiterallySignedStringMap​(it.unimi.dsi.fastutil.objects.Object2LongFunction<? extends java.lang.CharSequence> function, it.unimi.dsi.fastutil.objects.ObjectBigList<? extends MutableString> list)
      Creates a new shift-add-xor signed string map using a given hash map.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean containsKey​(java.lang.Object o)  
      java.lang.Long get​(java.lang.Object o)
      Deprecated.
      long getLong​(java.lang.Object o)  
      it.unimi.dsi.fastutil.objects.ObjectBigList<? extends MutableString> list()
      Returns a list view of the domain of this string map (optional operation).
      static void main​(java.lang.String[] arg)  
      int size()
      Deprecated.
      long size64()
      Returns the intended number of keys in this function, or -1 if no such number exists.
      • 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.Function

        apply, clear
      • Methods inherited from interface java.util.function.Function

        compose
      • Methods inherited from interface it.unimi.dsi.fastutil.objects.Object2LongFunction

        andThen, andThenByte, andThenChar, andThenDouble, andThenFloat, andThenInt, andThenLong, andThenObject, andThenReference, andThenShort, applyAsLong, composeByte, composeChar, composeDouble, composeFloat, composeInt, composeLong, composeObject, composeReference, composeShort, defaultReturnValue, defaultReturnValue, getOrDefault, getOrDefault, put, put, remove, removeLong
    • Field Detail

      • function

        protected final it.unimi.dsi.fastutil.objects.Object2LongFunction<? extends java.lang.CharSequence> function
        The underlying map.
      • list

        protected final it.unimi.dsi.fastutil.objects.ObjectBigList<? extends MutableString> list
        The underlying list.
      • size

        protected final long size
        The size of list.
    • Constructor Detail

      • LiterallySignedStringMap

        public LiterallySignedStringMap​(it.unimi.dsi.fastutil.objects.Object2LongFunction<? extends java.lang.CharSequence> function,
                                        it.unimi.dsi.fastutil.objects.ObjectBigList<? extends MutableString> list)
        Creates a new shift-add-xor signed string map using a given hash map.
        Parameters:
        function - a function mapping each string in list to its ordinal position.
        list - a list of strings.
    • Method Detail

      • getLong

        public long getLong​(java.lang.Object o)
        Specified by:
        getLong in interface it.unimi.dsi.fastutil.objects.Object2LongFunction<java.lang.CharSequence>
      • get

        @Deprecated
        public java.lang.Long get​(java.lang.Object o)
        Deprecated.
        Specified by:
        get in interface it.unimi.dsi.fastutil.Function<java.lang.CharSequence,​java.lang.Long>
        Specified by:
        get in interface it.unimi.dsi.fastutil.objects.Object2LongFunction<java.lang.CharSequence>
      • size64

        public long size64()
        Description copied from interface: StringMap
        Returns the intended number of keys in this function, or -1 if no such number exists.

        Most function implementations will have some knowledge of the intended number of keys in their domain. In some cases, however, this might not be possible. This default implementation, in particular, returns -1.

        Specified by:
        size64 in interface it.unimi.dsi.fastutil.Size64
        Specified by:
        size64 in interface StringMap<MutableString>
        Returns:
        the intended number of keys in this function, or -1 if that number is not available.
      • size

        @Deprecated
        public int size()
        Deprecated.
        Description copied from interface: StringMap
        Specified by:
        size in interface it.unimi.dsi.fastutil.Function<java.lang.CharSequence,​java.lang.Long>
        Specified by:
        size in interface it.unimi.dsi.fastutil.Size64
        Specified by:
        size in interface StringMap<MutableString>
      • containsKey

        public boolean containsKey​(java.lang.Object o)
        Specified by:
        containsKey in interface it.unimi.dsi.fastutil.Function<java.lang.CharSequence,​java.lang.Long>
      • list

        public it.unimi.dsi.fastutil.objects.ObjectBigList<? extends MutableString> list()
        Description copied from interface: StringMap
        Returns 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:
        list in interface StringMap<MutableString>
        Returns:
        a list view of the domain of this string map, or null if this map does not support this operation.
      • main

        public static void main​(java.lang.String[] arg)
                         throws java.io.IOException,
                                com.martiansoftware.jsap.JSAPException,
                                java.lang.ClassNotFoundException,
                                java.lang.SecurityException,
                                java.lang.NoSuchMethodException
        Throws:
        java.io.IOException
        com.martiansoftware.jsap.JSAPException
        java.lang.ClassNotFoundException
        java.lang.SecurityException
        java.lang.NoSuchMethodException