Class IntHashMap<T>


  • public class IntHashMap<T>
    extends java.lang.Object
    A hash table that maps int keys to Object values.
    • Constructor Summary

      Constructors 
      Constructor Description
      IntHashMap()
      Initializes a map with a capacity of 8 and a load factor of 0,25.
      IntHashMap​(int capacity)
      Initializes a map with the given capacity and a load factor of 0,25.
      IntHashMap​(int capacity, double factor)
      Constructs a new map with initial capacity, and load factor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears the map.
      IntHashMap<T> copy()
      Create a copy of the IntHashMap
      T get​(int key)
      Gets the value for this key.
      IntIterator keyIterator()
      Get an iterator over the keys
      IntSet keySet()
      Get the set of integer keys present in this IntHashSet
      T put​(int key, T value)
      Adds a key-value pair to the map.
      boolean remove​(int key)
      Removes a key from the map.
      int size()
      Gets the size of the map.
      java.util.Iterator<T> valueIterator()
      Get an iterator over the values
      java.lang.Iterable<T> valueSet()
      Get the collection of values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IntHashMap

        public IntHashMap()
        Initializes a map with a capacity of 8 and a load factor of 0,25.
      • IntHashMap

        public IntHashMap​(int capacity)
        Initializes a map with the given capacity and a load factor of 0,25.
        Parameters:
        capacity - the initial capacity.
      • IntHashMap

        public IntHashMap​(int capacity,
                          double factor)
        Constructs a new map with initial capacity, and load factor.

        The capacity is the number of keys that can be mapped without resizing the arrays in which keys and values are stored. For efficiency, only a fraction of the elements in those arrays are used. That fraction is the specified load factor. The initial length of the arrays equals the smallest power of two not less than the ratio capacity/factor. The capacity of the map is increased, as necessary. The maximum number of keys that can be mapped is 2^30.

        Parameters:
        capacity - the initial capacity.
        factor - the load factor.
    • Method Detail

      • clear

        public void clear()
        Clears the map.
      • get

        public T get​(int key)
        Gets the value for this key.
        Parameters:
        key - Key
        Returns:
        the value, null if not found.
      • size

        public int size()
        Gets the size of the map.
        Returns:
        the size (the number of entries in the map)
      • remove

        public boolean remove​(int key)
        Removes a key from the map.
        Parameters:
        key - Key to remove
        Returns:
        true if the value was removed
      • put

        public T put​(int key,
                     T value)
        Adds a key-value pair to the map.
        Parameters:
        key - Key
        value - Value
        Returns:
        the value that was previously associated with the key, or null if there was no previous value
      • keyIterator

        public IntIterator keyIterator()
        Get an iterator over the keys
        Returns:
        an iterator over the integer keys in the map
      • valueIterator

        public java.util.Iterator<T> valueIterator()
        Get an iterator over the values
        Returns:
        an iterator over the values in the map
      • valueSet

        public java.lang.Iterable<T> valueSet()
        Get the collection of values. (Despite the name, this is not a set: it may contain duplicates.)
        Returns:
        the set of values as an iterable collection
      • copy

        public IntHashMap<T> copy()
        Create a copy of the IntHashMap
        Returns:
        a copy of this map
      • keySet

        public IntSet keySet()
        Get the set of integer keys present in this IntHashSet
        Returns:
        the set of integer keys present in this IntHashSet