Class IntIntHashtable


  • public class IntIntHashtable
    extends java.lang.Object
    Class that implements a hashtable with int keys and int values. Because this class uses array of primitives to store the information, it serializes very fast. This implementation uses separate chaining to resolve collisions.
    • Constructor Summary

      Constructors 
      Constructor Description
      IntIntHashtable()
      Default constructor creates a table with an initial default capacity.
      IntIntHashtable​(int capacity)
      Constructor creates a table with an initial given capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(int key)
      Return true if the given key is in the hashtable.
      int get​(int key)
      Returns the value for the given key.
      int[] getKeys()
      Returns an array containing all the int keys.
      void put​(int key, int value)
      Adds a key/value pair to the hashtable.
      int remove​(int key)
      Removes a key/value from the hashtable
      void removeAll()
      Remove all entries from the hashtable.
      int size()
      Return the number of key/value pairs stored in the hashtable.
      • Methods inherited from class java.lang.Object

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

      • IntIntHashtable

        public IntIntHashtable()
        Default constructor creates a table with an initial default capacity.
      • IntIntHashtable

        public IntIntHashtable​(int capacity)
        Constructor creates a table with an initial given capacity. The capacity will be adjusted to the next highest prime in the PRIMES table.
        Parameters:
        capacity - the initial capacity.
    • Method Detail

      • put

        public void put​(int key,
                        int value)
        Adds a key/value pair to the hashtable. If the key is already in the table, the old value is replaced with the new value. If the hashtable is already full, the hashtable will attempt to approximately double in size (it will use a prime number), and all the current entries will be rehashed.
        Parameters:
        key - the key for the new entry.
        value - the value for the new entry.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - thrown if the maximum capacity is reached.
      • get

        public int get​(int key)
                throws NoValueException
        Returns the value for the given key.
        Parameters:
        key - the key for which to retrieve a value.
        Throws:
        NoValueException - thrown if there is no value for the given key.
      • remove

        public int remove​(int key)
                   throws NoValueException
        Removes a key/value from the hashtable
        Parameters:
        key - the key to remove from the hashtable.
        Returns:
        true if key is found and removed, false otherwise.
        Throws:
        NoValueException
        NoValueException - thrown if there is no value for the given key.
      • removeAll

        public void removeAll()
        Remove all entries from the hashtable.
      • contains

        public boolean contains​(int key)
        Return true if the given key is in the hashtable.
        Parameters:
        key - the key to be tested for existence in the hashtable.
      • size

        public int size()
        Return the number of key/value pairs stored in the hashtable.
      • getKeys

        public int[] getKeys()
        Returns an array containing all the int keys.