Class StringKeyIndexer

  • All Implemented Interfaces:
    java.io.Serializable

    public class StringKeyIndexer
    extends java.lang.Object
    implements java.io.Serializable
    This class converts arbitrary Strings into compacted int indexes suitable for use as indexes into an array or table. Whenever a new key is added, the smallest unused index is allocated and associated with that key. Basically hashes the keys into linked lists using the IntListIndexer class, where all values in a list have the same hashcode. Does most of the work in implementing a seperate chaining version of a hashtable - the only thing missing is the values which are stored in the individual implementations of the various hashtables.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      StringKeyIndexer()
      Constructs a StringKeyIndexer with a default capacity.
      StringKeyIndexer​(int capacity)
      Constructs a StringKeyIndexer with a given initial capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Remove all keys.
      int get​(java.lang.String key)
      Returns the index for the given key, or -1 if key is not in the table.
      int getCapacity()
      Returns the current size of the key table.
      java.util.Iterator<java.lang.String> getKeyIterator()
      Returns an iterator over all the keys.
      java.lang.String[] getKeys()
      Returns an array containing all the keys stored in this object.
      int getSize()
      Returns the number of keys stored in the table.
      int put​(java.lang.String key)
      Returns an index that will always be associated to the given key as long as the key remains in the table.
      int remove​(java.lang.String key)
      Removes the key from the table.
      • Methods inherited from class java.lang.Object

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

      • StringKeyIndexer

        public StringKeyIndexer()
        Constructs a StringKeyIndexer with a default capacity.
      • StringKeyIndexer

        public StringKeyIndexer​(int capacity)
        Constructs a StringKeyIndexer with a given initial capacity.
        Parameters:
        capacity - the initial capacity.
    • Method Detail

      • put

        public int put​(java.lang.String key)
        Returns an index that will always be associated to the given key as long as the key remains in the table. If the key already exists, then the index where that key is stored is returned. If the key is new, then a new index is allocated, the key is stored at that index, and the new index is returned.
        Parameters:
        key - the key to be stored.
        Returns:
        index for key, or -1 if there was no room to put the key.
        Throws:
        java.lang.IndexOutOfBoundsException - thrown if this object is at maximum capacity.
      • get

        public int get​(java.lang.String key)
        Returns the index for the given key, or -1 if key is not in the table.
        Parameters:
        key - the key for which to find an index.
      • remove

        public int remove​(java.lang.String key)
        Removes the key from the table.
        Parameters:
        key - the key to remove.
        Returns:
        index of the key if the key was found, -1 if key did not exist in the table
      • getSize

        public int getSize()
        Returns the number of keys stored in the table.
      • getCapacity

        public int getCapacity()
        Returns the current size of the key table.
      • clear

        public void clear()
        Remove all keys.
      • getKeys

        public java.lang.String[] getKeys()
        Returns an array containing all the keys stored in this object.
      • getKeyIterator

        public java.util.Iterator<java.lang.String> getKeyIterator()
        Returns an iterator over all the keys.
        Returns:
        an iterator over all the keys.