gnu.kawa.util
Class GeneralHashTable
java.lang.Object
gnu.kawa.util.GeneralHashTable
- Direct Known Subclasses:
- NameLookup
public class GeneralHashTable
- extends java.lang.Object
A generic hash table.
Supports deletions, and re-allocates the table when too big.
The equivalence relation can be customized.
Method Summary |
void |
clear()
|
java.lang.Object |
get(java.lang.Object key,
java.lang.Object defaultValue)
|
HashNode |
getNode(java.lang.Object key)
|
int |
hash(HashNode node)
|
int |
hash(java.lang.Object key)
Calculate hash code of a key. |
protected HashNode |
makeEntry(java.lang.Object key,
int hash,
java.lang.Object value)
Allocate a new node in the hash table. |
boolean |
matches(java.lang.Object key,
int hash,
HashNode node)
|
boolean |
matches(java.lang.Object value1,
java.lang.Object value2)
Compare two keys for equivalence. |
protected static HashNode |
next(HashNode node)
|
java.lang.Object |
put(java.lang.Object key,
int hash,
java.lang.Object value)
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
|
protected void |
rehash()
|
java.lang.Object |
remove(java.lang.Object key)
|
int |
size()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
table
protected HashNode[] table
mask
protected int mask
num_bindings
protected int num_bindings
GeneralHashTable
public GeneralHashTable()
GeneralHashTable
public GeneralHashTable(int capacity)
makeEntry
protected HashNode makeEntry(java.lang.Object key,
int hash,
java.lang.Object value)
- Allocate a new node in the hash table.
hash
public int hash(java.lang.Object key)
- Calculate hash code of a key.
You may need to override this if you override the
matches
method.
hash
public int hash(HashNode node)
matches
public boolean matches(java.lang.Object key,
int hash,
HashNode node)
matches
public boolean matches(java.lang.Object value1,
java.lang.Object value2)
- Compare two keys for equivalence.
Override this and the
hash(Object)
method if you want
a different equivalence relation.
get
public java.lang.Object get(java.lang.Object key,
java.lang.Object defaultValue)
getNode
public HashNode getNode(java.lang.Object key)
put
public java.lang.Object put(java.lang.Object key,
java.lang.Object value)
put
public java.lang.Object put(java.lang.Object key,
int hash,
java.lang.Object value)
remove
public java.lang.Object remove(java.lang.Object key)
rehash
protected void rehash()
clear
public void clear()
size
public int size()
next
protected static HashNode next(HashNode node)