Algorithm
Development Kit 1.0

algs.model.search
Class ListHashTable<V>

java.lang.Object
  extended by algs.model.search.HashTable<V,V>
      extended by algs.model.search.ListHashTable<V>
All Implemented Interfaces:
IHashtableAccess<V,V>

public class ListHashTable<V>
extends HashTable<V,V>

HashTable that uses list collision to store objects whose keys collide.

Stores the objects as the keys themselves.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman, Gary Pollice

Constructor Summary
ListHashTable(int tableSize)
          Construct initial Hash Table using default hash method that relies on a properly formed hashCode() implementation.
ListHashTable(int tableSize, IHash<V> hashMethod)
          Construct initial Hash Table using desired hash method.
 
Method Summary
 void add(V k)
          ListHashTable objects add elements who are themselves keys.
 V add(V k, V v)
          Associate element v with key k.
 void load(java.util.Iterator<V> it)
          Bulk load elements into the Hash Table from the Iterator.
 V remove(V v)
          Remove the entry from the hash table.
 java.lang.String report()
          Every Hash Table has the ability to report interesting statistics about itself.
 boolean search(V v)
          Search for the desired value in the HashTable.
 
Methods inherited from class algs.model.search.HashTable
remove, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListHashTable

public ListHashTable(int tableSize,
                     IHash<V> hashMethod)
Construct initial Hash Table using desired hash method.

Parameters:
tableSize - desired size.
hashMethod - method to use when hashing elements.

ListHashTable

public ListHashTable(int tableSize)
Construct initial Hash Table using default hash method that relies on a properly formed hashCode() implementation.

Parameters:
tableSize - desired size.
Method Detail

search

public boolean search(V v)
Search for the desired value in the HashTable.

Only succeeds if V overrides the equals (Object o) method

Parameters:
v - the searched-for value
Returns:
true if element v is found in the HashTable; false otherwise.

load

public void load(java.util.Iterator<V> it)
Bulk load elements into the Hash Table from the Iterator. If previous objects were associated with the keys from these items they are discarded.

Parameters:
it - Iterator of the elements to be added into the Hash Table.

add

public void add(V k)
ListHashTable objects add elements who are themselves keys.

Parameters:
k - the key (and value) of the element to be added.

add

public V add(V k,
             V v)
Description copied from interface: IHashtableAccess
Associate element v with key k.

Parameters:
k - key to be added to the Hash table entries
v - target item to be associated with the key
Returns:
null if no such element associated in the Hash Table with the given key; otherwise returns V objects that was previously associated with that object.

remove

public V remove(V v)
Description copied from interface: IHashtableAccess
Remove the entry from the hash table.

Parameters:
v - key of target item to be removed.
Returns:
object of class V if previously associated in the Hash table with the given key; null otherwise.

report

public java.lang.String report()
Description copied from class: HashTable
Every Hash Table has the ability to report interesting statistics about itself.

Defined by subclasses

Specified by:
report in class HashTable<V,V>

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.