DataStructures
Interface LookupTable<K,V>

Type Parameters:
K - the type of objects serving as keys
V - the type of objects serving as values
All Superinterfaces:
java.lang.Iterable<LookupTable.Entry<K,V>>
All Known Implementing Classes:
DoubleHashingTable, ProbingHashTable, QuadraticProbingTable

public interface LookupTable<K,V>
extends java.lang.Iterable<LookupTable.Entry<K,V>>

A simple interface for a lookup table. Enables objects to be stored and retrieved using keys. Any object can be used as a key and any object can be used as the corresponding value.

Author:
Peter Williams
See Also:
Iterable

Nested Class Summary
static interface LookupTable.Entry<K,V>
          A class of objects returned by iteration over entries.
 
Method Summary
 void add(K key, V value)
          Adds the specified entry to the table.
 boolean contains(K key)
          Returns true if the table contains an entry for this key.
 boolean isEmpty()
          Tests if the table is empty.
 java.util.Iterator<LookupTable.Entry<K,V>> iterator()
          Returns an iteration over the entries in this lookup table.
 V lookup(K key)
          Returns the value associated with the specified key.
 void remove(K key)
          Removes the entry corresponding to the key.
 int size()
          Returns the number of entries in the table.
 

Method Detail

isEmpty

boolean isEmpty()
Tests if the table is empty.

Returns:
the status of the table

size

int size()
Returns the number of entries in the table.

Returns:
the number of entries.

contains

boolean contains(K key)
Returns true if the table contains an entry for this key.

Parameters:
key - the key to be searched for
Returns:
true if the table contains an entry for this key

add

void add(K key,
         V value)
Adds the specified entry to the table. If the key is already present, its value is overwritten.

Parameters:
key - the key of the entry
value - the value of the entry

remove

void remove(K key)
Removes the entry corresponding to the key. Does nothing if the key is not present.

Parameters:
key - the key of the entry to be removed

lookup

V lookup(K key)
Returns the value associated with the specified key.

Parameters:
key - the key to be searched for
Returns:
the value for the key
Throws:
NoSuchElementException - if key is not present

iterator

java.util.Iterator<LookupTable.Entry<K,V>> iterator()
Returns an iteration over the entries in this lookup table. The next method of the iterator returns a (key, value) pair in the form of a LookupTable.Entry<K,V>

Specified by:
iterator in interface java.lang.Iterable<LookupTable.Entry<K,V>>
Returns:
an iteration over the entries in this lookup table
See Also:
LookupTable.Entry