Class FastHashMap<K,​V>

  • Type Parameters:
    K -
    V -
    All Implemented Interfaces:
    java.lang.Iterable<FastHashMap.Entry<K,​V>>

    public class FastHashMap<K,​V>
    extends java.lang.Object
    implements java.lang.Iterable<FastHashMap.Entry<K,​V>>
    Fast hash map implementation which uses array storage along with quadratic probing to resolve collisions. The capacity is doubled when the load goes beyond 50% and is halved when the load drops below 20%.
    • Constructor Summary

      Constructors 
      Constructor Description
      FastHashMap()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private FastHashMap.Entry<K,​V>[] alloc​(int size)
      Wrap the entry array allocation because it requires silencing some generics warnings.
      void clear()  
      boolean containsKey​(K k)  
      V get​(K k)  
      java.util.Iterator<FastHashMap.Entry<K,​V>> iterator()  
      V put​(K k, V v)  
      void remove​(K k)  
      private void resize​(int capacity)
      Resize internal storage to the specified capacity.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • FastHashMap

        public FastHashMap()
    • Method Detail

      • clear

        public void clear()
      • put

        public V put​(K k,
                     V v)
      • get

        public V get​(K k)
      • containsKey

        public boolean containsKey​(K k)
      • remove

        public void remove​(K k)
      • resize

        private void resize​(int capacity)
        Resize internal storage to the specified capacity. The capacity must be a power of two.
        Parameters:
        capacity - new capacity for the internal array
      • alloc

        private FastHashMap.Entry<K,​V>[] alloc​(int size)
        Wrap the entry array allocation because it requires silencing some generics warnings.
        Parameters:
        size - number of elements to allocate
        Returns:
      • iterator

        public java.util.Iterator<FastHashMap.Entry<K,​V>> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<K>