Class IntToIntHashMap

  • All Implemented Interfaces:
    java.io.Serializable

    public class IntToIntHashMap
    extends java.lang.Object
    implements java.io.Serializable
    A hash table that maps int keys to int values.
    Author:
    Dave Hale, Landmark Graphics, Dominique Devienne, Michael Kay: created this class based on IntHashMap
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      IntToIntHashMap()
      Initializes a map with a capacity of 8 and a load factor of 0,25.
      IntToIntHashMap​(int capacity)
      Initializes a map with the given capacity and a load factor of 0,25.
      IntToIntHashMap​(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.
      boolean find​(int key)
      Finds a key in the map.
      int get​(int key)
      Gets the value for this key.
      int getDefaultValue()
      Get the default value used to indicate an unused entry
      void put​(int key, int value)
      Adds a key-value pair to the map.
      boolean remove​(int key)
      Removes a key from the map.
      void setDefaultValue​(int defaultValue)
      Set the value to be returned to indicate an unused entry
      int size()
      Gets the size of the map.
      • Methods inherited from class java.lang.Object

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

      • IntToIntHashMap

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

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

        public IntToIntHashMap​(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

      • setDefaultValue

        public void setDefaultValue​(int defaultValue)
        Set the value to be returned to indicate an unused entry
      • getDefaultValue

        public int getDefaultValue()
        Get the default value used to indicate an unused entry
      • clear

        public void clear()
        Clears the map.
      • find

        public boolean find​(int key)
        Finds a key in the map.
        Parameters:
        key - Key
        Returns:
        true if the key is mapped
      • get

        public int 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
      • 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 void put​(int key,
                        int value)
        Adds a key-value pair to the map.
        Parameters:
        key - Key
        value - Value