Package gnu.kawa.util
Class IntHashTable
java.lang.Object
gnu.kawa.util.IntHashTable
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:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an Object-to-int hash table.IntHashTable
(int capacity) Construct an Object-to-int hash table with a specified amount of mappings. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all mappings from this map.int
getFromIndex
(int index) Return the value stored at the specified index in the table.int
Compute the hash code of a given object.int
Lookup a given key's value in the hash table.int
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
-
Field Details
-
objs
-
ints
protected int[] ints -
mask
protected int mask -
num_bindings
protected int num_bindings
-
-
Constructor Details
-
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 Details
-
hash
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
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
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
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
-
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.
-