|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.mhhe.clrs2e.DirectAddressTable
Implements a direct-address table from page 222 of Introduction
to Algorithms, Second edition. Indices into the direct-address
table are based on the Java hashCode
method applied to
objects, modulo the table size.
Field Summary | |
private int |
m
The number of entries in the direct-address table. |
private java.lang.Object[] |
table
The direct-address table. |
Constructor Summary | |
DirectAddressTable(int m)
Creates a new direct-address table of a given size. |
Method Summary | |
void |
delete(java.lang.Object handle)
Removes an element from a direct-address table. |
private int |
indexOf(java.lang.Comparable k)
Returns the index into the direct-address table at which an element is placed. |
java.lang.Object |
insert(java.lang.Comparable o)
Inserts an element into a direct-address table. |
java.lang.Object |
search(java.lang.Comparable k)
Searches for an element with a given key in a direct-address table. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private java.lang.Object[] table
k
is stored in table[k]
.
private int m
Constructor Detail |
public DirectAddressTable(int m)
m
- The size of the direct-address table.Method Detail |
public java.lang.Object insert(java.lang.Comparable o)
insert
in interface Dictionary
o
- The element to insert.
public void delete(java.lang.Object handle)
delete
in interface Dictionary
handle
- A handle to the element to remove.
java.lang.ClassCastException
- if handle does not reference an
object that implements Comparable
.public java.lang.Object search(java.lang.Comparable k)
search
in interface Dictionary
k
- The key being searched for.
null
if
there is no match.private int indexOf(java.lang.Comparable k)
DynamicSetElement
, the hash code of the element's
key is used. Otherwise, the hash code of the element itself is
used. In any case, the hash code is taken modulo the table
size.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |