Class HashTable

java.lang.Object
  |
  +--HashTable

public class HashTable
extends java.lang.Object

Class HashTable is a simple hash table example, as discussed in CSC 103 lecture notes week 5 and week 5, part 2 . Entries in a HashTable must implement the HashTableEntry interface.


Field Summary
protected  int DEFAULT_SIZE
          Default table size if zero-argument constructor is used
protected  HashTableEntry lastEntry
          Reference to most recent entry, for use by lookup and delete
protected  int size
          Table size
protected  HashTableEntry[] table
          The table array
 
Constructor Summary
HashTable()
          Construct an empty table of the default size of 1000 entries.
HashTable(int size)
          Construct an empty table of the given size.
 
Method Summary
 HashTable enter(HashTableEntry entry)
          Enter the given entry into this table if an entry of the same key is not already in the table.
 HashTableEntry lookup(java.lang.Object key)
          Lookup the entry of the given key.
 java.lang.String toString()
          Return this as a newline-delimited string of the form Entry 0: value ...
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_SIZE

protected final int DEFAULT_SIZE
Default table size if zero-argument constructor is used

size

protected final int size
Table size

table

protected HashTableEntry[] table
The table array

lastEntry

protected HashTableEntry lastEntry
Reference to most recent entry, for use by lookup and delete
Constructor Detail

HashTable

public HashTable()
Construct an empty table of the default size of 1000 entries.

HashTable

public HashTable(int size)
Construct an empty table of the given size.
Method Detail

enter

public HashTable enter(HashTableEntry entry)
                throws HashTableFull,
                       HashIndexInvalid
Enter the given entry into this table if an entry of the same key is not already in the table.

lookup

public HashTableEntry lookup(java.lang.Object key)
Lookup the entry of the given key. If found, return the entry, otherwise return null.

toString

public java.lang.String toString()
Return this as a newline-delimited string of the form Entry 0: value ... Entry size-1: value
Overrides:
toString in class java.lang.Object