Package dsa
Class SeparateChainingHashST<K,V>
java.lang.Object
dsa.SeparateChainingHashST<K,V>
- Type Parameters:
K
- the type of keys in the symbol table.V
- the type of values in the symbol table.
- All Implemented Interfaces:
BasicST<K,
V>
This data type provides an implementation of the basic symbol table (BasicST) API, using an array (hash table) of
LinearSearchST objects (chains) as the underlying data structure.
-
Constructor Summary
ConstructorDescriptionConstructs an empty symbol table.SeparateChainingHashST
(int m) Constructs an empty symbol table with m chains. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if this symbol table containskey
, andfalse
otherwise.void
Deleteskey
and the associated value from this symbol table.Returns the value associated withkey
in this symbol table, ornull
.boolean
isEmpty()
Returnstrue
if this symbol table is empty, andfalse
otherwise.keys()
Returns all the keys in this symbol table.static void
Unit tests the data type.void
Inserts thekey
andvalue
pair into this symbol table.int
size()
Returns the number of key-value pairs in this symbol table.toString()
Returns a string representation of this symbol table.
-
Constructor Details
-
SeparateChainingHashST
public SeparateChainingHashST()Constructs an empty symbol table. -
SeparateChainingHashST
public SeparateChainingHashST(int m) Constructs an empty symbol table with m chains.- Parameters:
m
- the number of chains.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returnstrue
if this symbol table is empty, andfalse
otherwise. -
size
public int size()Returns the number of key-value pairs in this symbol table. -
put
Inserts thekey
andvalue
pair into this symbol table. -
get
Returns the value associated withkey
in this symbol table, ornull
. -
contains
Returnstrue
if this symbol table containskey
, andfalse
otherwise. -
delete
Deleteskey
and the associated value from this symbol table. -
keys
Returns all the keys in this symbol table. -
toString
Returns a string representation of this symbol table. -
main
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-