Class FastHashMap<K,​V>

  • Type Parameters:
    K - the type of the key
    V - the type of the value
    All Implemented Interfaces:
    Serializable

    public class FastHashMap<K,​V>
    extends Object
    implements Serializable
    Simple hash map implementation taken from here https://github.com/mikvor/hashmapTest/blob/master/src/main/java/map/objobj/ObjObjMap.java No concrete license specified at the source. The project is public domain. Not thread-safe! Null support was removed.
    Since:
    3.10.0
    Author:
    René Schwietzke
    See Also:
    Serialized Form
    • Constructor Detail

      • FastHashMap

        public FastHashMap()
      • FastHashMap

        public FastHashMap​(int size,
                           float fillFactor)
    • Method Detail

      • get

        public V get​(K key)
      • put

        public V put​(K key,
                     V value)
      • remove

        public V remove​(K key)
      • size

        public int size()
      • keys

        public List<K> keys()
        Returns:
        a list of all keys
      • values

        public List<V> values()
        Returns:
        a list of all values
      • clear

        public void clear()
        Clears the map, reuses the data structure by clearing it out. It won't shrink the underlying array!
      • nextPowerOfTwo

        public static long nextPowerOfTwo​(long x)
        Return the least power of two greater than or equal to the specified value.

        Note that this function will return 1 when the argument is 0.

        Parameters:
        x - a long integer smaller than or equal to 262.
        Returns:
        the least power of two greater than or equal to the specified value.
      • arraySize

        public static int arraySize​(int expected,
                                    float f)
        Returns the least power of two smaller than or equal to 230 and larger than or equal to Math.ceil( expected / f ).
        Parameters:
        expected - the expected number of elements in a hash table.
        f - the load factor.
        Returns:
        the minimum possible size for a backing array.
        Throws:
        IllegalArgumentException - if the necessary size is larger than 230.