Package gnu.kawa.util
Class IntHashTable
- java.lang.Object
-
- gnu.kawa.util.IntHashTable
-
public class IntHashTable extends Object
A hash table that maps Object to int. This is a custom hash table optimised for Object-to-int maps. This is done to avoid unnecessary object allocation in the image set.- See Also:
OutPort
-
-
Field Summary
Fields Modifier and Type Field Description protected int[]
ints
protected int
mask
protected int
num_bindings
protected Object[]
objs
-
Constructor Summary
Constructors Constructor Description IntHashTable()
Construct an Object-to-int hash table.IntHashTable(int capacity)
Construct an Object-to-int hash table with a specified amount of mappings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all mappings from this map.int
getFromIndex(int index)
Return the value stored at the specified index in the table.int
hash(Object key)
Compute the hash code of a given object.int
lookup(Object key)
Lookup a given key's value in the hash table.int
lookup(Object key, int hash)
Find either the index of a key's value, or the index of an available space.int
putAtIndex(Object key, int value, int index)
Associates the specified key with the specified value in this map.protected void
rehash()
Expand the hash table when it exceeds the load factor.int
remove(Object key)
-
-
-
Field Detail
-
objs
protected Object[] objs
-
ints
protected int[] ints
-
mask
protected int mask
-
num_bindings
protected int num_bindings
-
-
Constructor Detail
-
IntHashTable
public IntHashTable()
Construct an Object-to-int hash table. The default size of the hash table is 64 mappings.
-
IntHashTable
public IntHashTable(int capacity)
Construct an Object-to-int hash table with a specified amount of mappings.- Parameters:
capacity
- The number of default mappings in this hash table.
-
-
Method Detail
-
hash
public int hash(Object key)
Compute the hash code of a given object.- Parameters:
key
- The object whose hash code is to be computed.- Returns:
- zero if the object is null, otherwise the identityHashCode
-
lookup
public int lookup(Object key, int hash)
Find either the index of a key's value, or the index of an available space.- Parameters:
key
- The key to whose value you want to find.hash
- The hash code of this key.- Returns:
- Either the index of the key's value, or an index pointing to unoccupied space.
-
lookup
public int lookup(Object key)
Lookup a given key's value in the hash table.- Parameters:
key
- The key whose value you want to find.- Returns:
- Either the index of the key's value, or an index pointing to unoccupied space.
-
getFromIndex
public int getFromIndex(int index)
Return the value stored at the specified index in the table.- Parameters:
index
- The index to inspect, as returned fromlookup(java.lang.Object, int)
- Returns:
- A non-negative integer if the index contains a non-null value, or -1 if it does.
-
putAtIndex
public int putAtIndex(Object key, int value, int index)
Associates the specified key with the specified value in this map.- Parameters:
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.index
- the index at which to place this binding, as returned fromlookup(java.lang.Object, int)
.- Returns:
- previous value associated with specified key, or -1 if there was no mapping for key.
-
remove
public int remove(Object key)
-
rehash
protected void rehash()
Expand the hash table when it exceeds the load factor. Rehash the existing objects.
-
clear
public void clear()
Removes all mappings from this map.
-
-