gnu.kawa.util

Class GeneralHashTable

public class GeneralHashTable extends Object

A generic hash table. Supports deletions, and re-allocates the table when too big. The equivalence relation can be customized.
Field Summary
protected intmask
protected intnum_bindings
protected HashNode[]table
Constructor Summary
GeneralHashTable()
GeneralHashTable(int capacity)
Method Summary
voidclear()
Objectget(Object key, Object defaultValue)
HashNodegetNode(Object key)
inthash(Object key)
Calculate hash code of a key.
inthash(HashNode node)
protected HashNodemakeEntry(Object key, int hash, Object value)
Allocate a new node in the hash table.
booleanmatches(Object key, int hash, HashNode node)
booleanmatches(Object value1, Object value2)
Compare two keys for equivalence.
protected static HashNodenext(HashNode node)
Objectput(Object key, Object value)
Objectput(Object key, int hash, Object value)
protected voidrehash()
Objectremove(Object key)
intsize()

Field Detail

mask

protected int mask

num_bindings

protected int num_bindings

table

protected HashNode[] table

Constructor Detail

GeneralHashTable

public GeneralHashTable()

GeneralHashTable

public GeneralHashTable(int capacity)

Method Detail

clear

public void clear()

get

public Object get(Object key, Object defaultValue)

getNode

public HashNode getNode(Object key)

hash

public int hash(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)

makeEntry

protected HashNode makeEntry(Object key, int hash, Object value)
Allocate a new node in the hash table.

matches

public boolean matches(Object key, int hash, HashNode node)

matches

public boolean matches(Object value1, Object value2)
Compare two keys for equivalence. Override this and the {@link #hash(Object)} method if you want a different equivalence relation.

next

protected static HashNode next(HashNode node)

put

public Object put(Object key, Object value)

put

public Object put(Object key, int hash, Object value)

rehash

protected void rehash()

remove

public Object remove(Object key)

size

public int size()