asd_library.hash
Class HashTable

java.lang.Object
  |
  +--asd_library.hash.HashTable
All Implemented Interfaces:
Dictionary_adt

public class HashTable
extends java.lang.Object
implements Dictionary_adt

Implementation of hash table


Field Summary
protected  int currentSize
           
protected  boolean[] isActive
           
protected  boolean isRehashable
           
protected  int k
           
protected  java.lang.Comparable[] table
          The array of elements.
 
Constructor Summary
HashTable()
          Costructs the hash table.
HashTable(int size)
          Costructs the hash table.
HashTable(int size, boolean rehash)
          Costructs the hash table.
 
Method Summary
 java.lang.Object find(java.lang.Comparable key)
          Returns the value to which this map maps the specified key.
static int hash(java.lang.String key, int tableSize)
          A hash routine for String objects.
 java.lang.Object insert(java.lang.Comparable key)
          Inserts the key x in this dictionary.
 void makeEmpty()
          Make the hash table logically empty.
 java.lang.Comparable remove(java.lang.Comparable key)
          Removes the mapping for this key from this dictionary if it is present
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

table

protected java.lang.Comparable[] table
The array of elements.


isActive

protected boolean[] isActive

currentSize

protected int currentSize

isRehashable

protected boolean isRehashable

k

protected int k
Constructor Detail

HashTable

public HashTable()
Costructs the hash table.


HashTable

public HashTable(int size)
Costructs the hash table.

Parameters:
size - the initial size of the hash table.

HashTable

public HashTable(int size,
                 boolean rehash)
Costructs the hash table.

Parameters:
size - the initial size of the hash table.
rehash - true if the table can be expanded, false otherwise.
Method Detail

insert

public java.lang.Object insert(java.lang.Comparable key)
Inserts the key x in this dictionary.

Specified by:
insert in interface Dictionary_adt
Parameters:
key - the element to insert
Returns:
the key if the table has at least one empty location, null otherwise

remove

public java.lang.Comparable remove(java.lang.Comparable key)
Removes the mapping for this key from this dictionary if it is present

Specified by:
remove in interface Dictionary_adt
Parameters:
key - the element to remove.

find

public java.lang.Object find(java.lang.Comparable key)
Returns the value to which this map maps the specified key.

Specified by:
find in interface Dictionary_adt
Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key.

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.

makeEmpty

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