|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectStringHash
public class StringHash
A fast but inflexible hash table where the keys are strings and the size is fixed. Handles consecutive keys gracefully, but doesn't support resizing, deletion, or iteration.
Nested Class Summary | |
---|---|
private class |
StringHash.Ent
Keeps track of a single entry in the hash table. |
Field Summary | |
---|---|
private int |
curSize
|
private StringHash.Ent[] |
ents
|
private int |
hashSize
|
static Tester |
tester
Basic regression test |
Constructor Summary | |
---|---|
StringHash(int maxSize)
Create the hash table that can comfortably hold the specified number of entries. |
Method Summary | |
---|---|
boolean |
contains(String key)
Checks if the hash contains an entry for the given key. |
Object |
get(String key)
Retrieves the entry for the given key. |
private int |
hashSlot(String key)
Calculate the hash slot for a given key |
void |
put(String key,
Object val)
Sets the entry for the given key number. |
int |
size()
Tells how many entries are currently in the hash table |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final int hashSize
private final StringHash.Ent[] ents
private int curSize
public static final Tester tester
Constructor Detail |
---|
public StringHash(int maxSize)
maxSize
- Max # of entriesMethod Detail |
---|
public void put(String key, Object val)
private final int hashSlot(String key)
public boolean contains(String key)
public Object get(String key)
key
- Key to look for
public int size()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |