Class IntHashMap<V>

  • All Implemented Interfaces:
    IntMap<V>

    public class IntHashMap<V>
    extends Object
    implements IntMap<V>
    The simple map for primitive types base on Robin-hood hashing with backward shift.
    • Constructor Summary

      Constructors 
      Constructor Description
      IntHashMap()
      Default constructor.
      IntHashMap​(int cap)
      Create map with preallocated array.
      IntHashMap​(IntMap<? extends V> other)
      Copy constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes all of the mappings from this map.
      boolean containsKey​(int key)
      Returns true if the map contains the key, otherwise false.
      boolean containsValue​(V val)
      Returns true if the map contains one or more values, otherwise false.
      protected int distance​(int curIdx, int key)
      Returns size of shift from ideal position computing via index(key).
      <E extends Throwable>
      void
      forEach​(IntMap.EntryConsumer<V,​E> act)
      This method work under a read lock, be careful with long operations inside.
      V get​(int key)
      Returns value associated with the key. if the map doesn't contain the key, returns null.
      protected int index​(int key)
      Position in entites array.
      boolean isEmpty()
      Returns true if this map contains no key-value mappings.
      int[] keys()
      Returns array of keys.
      V put​(int key, V val)
      Save the pair into the map.
      V putIfAbsent​(int key, V val)
      Does put into the map if a pair isn't present, otherwise returns stored value.
      V remove​(int key)
      int size()
      Returns count of elements.
      String toString()
      Collection<V> values()
      Returns a collection of values.
    • Field Detail

      • INITIAL_CAPACITY

        public static final int INITIAL_CAPACITY
        Initial capacity.
        See Also:
        Constant Field Values
      • MAXIMUM_CAPACITY

        public static final int MAXIMUM_CAPACITY
        Maximum capacity.
        See Also:
        Constant Field Values
    • Constructor Detail

      • IntHashMap

        public IntHashMap()
        Default constructor.
      • IntHashMap

        public IntHashMap​(int cap)
        Create map with preallocated array.
      • IntHashMap

        public IntHashMap​(IntMap<? extends V> other)
        Copy constructor.
    • Method Detail

      • get

        public V get​(int key)
        Returns value associated with the key. if the map doesn't contain the key, returns null.
        Specified by:
        get in interface IntMap<V>
        Parameters:
        key - key with which the specified value is to be associated.
      • put

        public V put​(int key,
                     V val)
        Save the pair into the map. If a pair is present, returns old value and store new.
        Specified by:
        put in interface IntMap<V>
        Parameters:
        key - key with which the specified value is to be associated.
        val - value to be associated with the specified key.
      • remove

        public V remove​(int key)
        Specified by:
        remove in interface IntMap<V>
        Parameters:
        key - key with which the specified value is to be associated.
      • putIfAbsent

        public V putIfAbsent​(int key,
                             V val)
        Does put into the map if a pair isn't present, otherwise returns stored value.
        Specified by:
        putIfAbsent in interface IntMap<V>
        Parameters:
        key - key with which the specified value is to be associated..
        val - value to be associated with the specified key..
      • size

        public int size()
        Returns count of elements.
        Specified by:
        size in interface IntMap<V>
      • isEmpty

        public boolean isEmpty()
        Returns true if this map contains no key-value mappings.
        Specified by:
        isEmpty in interface IntMap<V>
      • keys

        public int[] keys()
        Returns array of keys.
        Specified by:
        keys in interface IntMap<V>
      • containsKey

        public boolean containsKey​(int key)
        Returns true if the map contains the key, otherwise false.
        Specified by:
        containsKey in interface IntMap<V>
        Parameters:
        key - tests key value.
      • containsValue

        public boolean containsValue​(V val)
        Returns true if the map contains one or more values, otherwise false.
        Specified by:
        containsValue in interface IntMap<V>
        Parameters:
        val - value to be associated with the specified key.
      • clear

        public void clear()
        Removes all of the mappings from this map.
        Specified by:
        clear in interface IntMap<V>
      • distance

        protected int distance​(int curIdx,
                               int key)
        Returns size of shift from ideal position computing via index(key).
        Parameters:
        curIdx - Current index.
        key - Target key.
      • index

        protected int index​(int key)
        Position in entites array.
        Parameters:
        key - Targert key.