Interface Function<K,​V>

  • All Known Subinterfaces:
    Char2ObjectFunction<V>, Char2ObjectMap<V>
    All Known Implementing Classes:
    AbstractChar2ObjectFunction, AbstractChar2ObjectMap, Char2ObjectFunctions.EmptyFunction, Char2ObjectFunctions.Singleton, Char2ObjectFunctions.SynchronizedFunction, Char2ObjectFunctions.UnmodifiableFunction, Char2ObjectOpenHashMap

    public interface Function<K,​V>
    A function mapping keys into values.

    Instances of this class represent functions: the main difference with Map is that functions do not in principle allow enumeration of their domain or range. The need for this interface lies in the existence of several highly optimized implementations of functions (e.g., minimal perfect hashes) which do not actually store their domain or range explicitly. In case the domain is known, containsKey(Object) can be used to perform membership queries.

    The choice of naming all methods exactly as in Map makes it possible for all type-specific maps to extend type-specific functions (e.g., org.codelibs.jhighlight.fastutil.ints.Int2IntMap extends org.codelibs.jhighlight.fastutil.ints.Int2IntFunction). However, size() is allowed to return -1 to denote that the number of keys is not available (e.g., in the case of a string hash function).

    Note that there is an org.codelibs.jhighlight.fastutil.objects.Object2ObjectFunction that can also set its default return value.

    Warning: Equality of functions is not specified by contract, and it will usually be by reference, as there is no way to enumerate the keys and establish whether two functions represent the same mathematical entity.

    See Also:
    Map
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void clear()
      Removes all associations from this function (optional operation).
      boolean containsKey​(Object key)
      Returns true if this function contains a mapping for the specified key.
      V get​(Object key)
      Returns the value associated by this function to the specified key.
      V put​(K key, V value)
      Associates the specified value with the specified key in this function (optional operation).
      V remove​(Object key)
      Removes this key and the associated value from this function if it is present (optional operation).
      int size()
      Returns the intended number of keys in this function, or -1 if no such number exists.
    • Method Detail

      • put

        V put​(K key,
              V value)
        Associates the specified value with the specified key in this function (optional operation).
        Parameters:
        key - the key.
        value - the value.
        Returns:
        the old value, or null if no value was present for the given key.
        See Also:
        Map.put(Object,Object)
      • get

        V get​(Object key)
        Returns the value associated by this function to the specified key.
        Parameters:
        key - the key.
        Returns:
        the corresponding value, or null if no value was present for the given key.
        See Also:
        Map.get(Object)
      • containsKey

        boolean containsKey​(Object key)
        Returns true if this function contains a mapping for the specified key.

        Note that for some kind of functions (e.g., hashes) this method will always return true.

        Parameters:
        key - the key.
        Returns:
        true if this function associates a value to key.
        See Also:
        Map.containsKey(Object)
      • remove

        V remove​(Object key)
        Removes this key and the associated value from this function if it is present (optional operation).
        Parameters:
        key -
        Returns:
        the old value, or null if no value was present for the given key.
        See Also:
        Map.remove(Object)
      • size

        int size()
        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.

        Returns:
        the intended number of keys in this function, or -1 if that number is not available.
      • clear

        void clear()
        Removes all associations from this function (optional operation).
        See Also:
        Map.clear()