gnu.kawa.util

Class GeneralHashTable


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.

Field Summary

protected int
num_bindings
protected HashNode[]
table

Constructor Summary

GeneralHashTable()
GeneralHashTable(int capacity)

Method Summary

void
clear()
Object
get(Object key, Object defaultValue)
HashNode
getNode(Object key)
int
hash(Object key)
Calculate hash code of a key.
int
hash(HashNode node)
protected HashNode
makeEntry(Object key, int hash, Object value)
Allocate a new node in the hash table.
boolean
matches(Object value1, Object value2)
Compare two keys for equivalence.
boolean
matches(Object key, int hash, HashNode node)
protected static HashNode
next(HashNode node)
Object
put(Object key, Object value)
Object
put(Object key, int hash, Object value)
Object
remove(Object key)
int
size()

Field Details

num_bindings

protected int num_bindings

table

protected HashNode[] table

Constructor Details

GeneralHashTable

public GeneralHashTable()

GeneralHashTable

public GeneralHashTable(int capacity)

Method Details

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 value1,
                       Object value2)
Compare two keys for equivalence. Override this and the hash(Object) method if you want a different equivalence relation.

matches

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

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)

remove

public Object remove(Object key)

size

public int size()