Modifier and Type | Class and Description |
---|---|
class |
HashTable.HashIterator |
Constructor and Description |
---|
HashTable(int numberOfBuckets,
HashFunction hasher)
Initializes a new instance of HashTable.
|
Modifier and Type | Method and Description |
---|---|
boolean |
insert(java.lang.String key)
Add a key to the hash table, if it is not currently in the table
|
java.util.Iterator<java.lang.String> |
iterator()
Get an iterator that return the Strings stored in
the hash table one at a time.
|
java.util.Iterator<java.lang.String> |
iterator(int index)
Does not use the iterator above.
|
void |
print()
Print the entire hash table.
|
boolean |
remove(java.lang.String key)
Remove a key from the hash table
|
java.lang.String |
search(java.lang.String key)
Search for a key in the hash table
|
int |
size()
Get the number of elements in the hash table
|
int |
size(int index)
Get the number of elements in the hash table at the given index
|
public HashTable(int numberOfBuckets, HashFunction hasher)
Initialize the instance variables.
Note: when initializing the hashTable, make sure to allocate each entry in the HashTable
to a new a HashBucket or null, your choice.
numberOfBuckets
- the size of the hashTablehasher
- the type of hashing functionpublic boolean insert(java.lang.String key)
IHash
public boolean remove(java.lang.String key)
IHash
public java.lang.String search(java.lang.String key)
IHash
public int size()
IHash
public int size(int index)
IHash
public java.util.Iterator<java.lang.String> iterator()
IHash
public java.util.Iterator<java.lang.String> iterator(int index)