Class FastHashMap<K,V>

java.lang.Object
org.htmlunit.cyberneko.util.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
See Also:
  • Field Details

    • FREE_KEY

      private static final Object FREE_KEY
    • REMOVED_KEY

      private static final Object REMOVED_KEY
    • m_data_

      private Object[] m_data_
      Keys and values
    • m_fillFactor_

      private final float m_fillFactor_
      Fill factor, must be between (0 and 1)
    • m_threshold_

      private int m_threshold_
      We will resize a map once it reaches this size
    • m_size_

      private int m_size_
      Current map size
    • m_mask_

      private int m_mask_
      Mask to calculate the original position
    • m_mask2_

      private int m_mask2_
      Mask to wrap the actual array pointer
  • Constructor Details

    • FastHashMap

      public FastHashMap()
    • FastHashMap

      public FastHashMap(int size, float fillFactor)
  • Method Details

    • get

      public V get(K key)
    • put

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

      public V remove(K key)
    • size

      public int size()
    • rehash

      private void rehash(int newCapacity)
    • 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!
    • getStartIndex

      private int getStartIndex(Object key)
    • 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.
    • readObject

      private void readObject(ObjectInputStream aInputStream) throws ClassNotFoundException, IOException
      We have to overwrite the import due to the use of static object as marker
      Parameters:
      aInputStream - the inputstream to read from
      Throws:
      IOException - when the reading from the source fails
      ClassNotFoundException - in case we cannot restore a class
    • writeObject

      private void writeObject(ObjectOutputStream aOutputStream) throws IOException
      We have to overwrite the export due to the use of static object as marker
      Parameters:
      aOutputStream - the stream to write to
      Throws:
      IOException - when a problem during writing occurs