DataStructures
Class SeparateChainingHashTable

java.lang.Object
  |
  +--DataStructures.SeparateChainingHashTable

public class SeparateChainingHashTable
extends java.lang.Object

Separate chaining table implementation of hash tables. Note that all "matching" is based on the equals method.


Constructor Summary
SeparateChainingHashTable()
          Construct the hash table.
SeparateChainingHashTable(int size)
          Construct the hash table.
 
Method Summary
 Hashable find(Hashable x)
          Find an item in the hash table.
static int hash(java.lang.String key, int tableSize)
          A hash routine for String objects.
 void insert(Hashable x)
          Insert into the hash table.
static void main(java.lang.String[] args)
           
 void makeEmpty()
          Make the hash table logically empty.
 void remove(Hashable x)
          Remove from the hash table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SeparateChainingHashTable

public SeparateChainingHashTable()
Construct the hash table.

SeparateChainingHashTable

public SeparateChainingHashTable(int size)
Construct the hash table.
Parameters:
size - approximate table size.
Method Detail

insert

public void insert(Hashable x)
Insert into the hash table. If the item is already present, then do nothing.
Parameters:
x - the item to insert.

remove

public void remove(Hashable x)
Remove from the hash table.
Parameters:
x - the item to remove.

find

public Hashable find(Hashable x)
Find an item in the hash table.
Parameters:
x - the item to search for.
Returns:
the matching item, or null if not found.

makeEmpty

public void makeEmpty()
Make the hash table logically empty.

hash

public static int hash(java.lang.String key,
                       int tableSize)
A hash routine for String objects.
Parameters:
key - the String to hash.
tableSize - the size of the hash table.
Returns:
the hash value.

main

public static void main(java.lang.String[] args)