Package gnu.kawa.util
Class AbstractWeakHashTable<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- gnu.kawa.util.AbstractHashTable<AbstractWeakHashTable.WEntry<K,V>,K,V>
-
- gnu.kawa.util.AbstractWeakHashTable<K,V>
-
- All Implemented Interfaces:
Map<K,V>
public abstract class AbstractWeakHashTable<K,V> extends AbstractHashTable<AbstractWeakHashTable.WEntry<K,V>,K,V>
A hash table with weakly referenced keys and values. Unlike java.util.WeakHashMap, this is useful when a value object contain a strong reference to the corresponding keys.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractWeakHashTable.WEntry<K,V>
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
-
Fields inherited from class gnu.kawa.util.AbstractHashTable
DEFAULT_INITIAL_SIZE, mask, num_bindings, table
-
-
Constructor Summary
Constructors Constructor Description AbstractWeakHashTable()
AbstractWeakHashTable(int capacity)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected AbstractWeakHashTable.WEntry<K,V>[]
allocEntries(int n)
Allocate Entry[n].protected void
cleanup()
V
get(Object key, V defaultValue)
Find value for given key.protected int
getEntryHashCode(AbstractWeakHashTable.WEntry<K,V> entry)
Extract hash-code from Entry.protected AbstractWeakHashTable.WEntry<K,V>
getEntryNext(AbstractWeakHashTable.WEntry<K,V> entry)
Extract next Entry in same hash-bucket.protected abstract K
getKeyFromValue(V value)
protected V
getValueIfMatching(AbstractWeakHashTable.WEntry<K,V> node, Object key)
int
hash(Object key)
Calculate hash code of a key.protected AbstractWeakHashTable.WEntry<K,V>
makeEntry(K key, int hash, V value)
Allocate a new node in the hash table.V
put(K key, V value)
protected void
setEntryNext(AbstractWeakHashTable.WEntry<K,V> entry, AbstractWeakHashTable.WEntry<K,V> next)
Set next Entry in same hash-bucket.protected boolean
valuesEqual(V oldValue, V newValue)
-
Methods inherited from class gnu.kawa.util.AbstractHashTable
clear, entrySet, get, getNode, getOrDefault, hashToIndex, matches, matches, put, rehash, remove, size
-
Methods inherited from class java.util.AbstractMap
clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
getEntryHashCode
protected int getEntryHashCode(AbstractWeakHashTable.WEntry<K,V> entry)
Description copied from class:AbstractHashTable
Extract hash-code from Entry.- Specified by:
getEntryHashCode
in classAbstractHashTable<AbstractWeakHashTable.WEntry<K,V>,K,V>
-
getEntryNext
protected AbstractWeakHashTable.WEntry<K,V> getEntryNext(AbstractWeakHashTable.WEntry<K,V> entry)
Description copied from class:AbstractHashTable
Extract next Entry in same hash-bucket.- Specified by:
getEntryNext
in classAbstractHashTable<AbstractWeakHashTable.WEntry<K,V>,K,V>
-
setEntryNext
protected void setEntryNext(AbstractWeakHashTable.WEntry<K,V> entry, AbstractWeakHashTable.WEntry<K,V> next)
Description copied from class:AbstractHashTable
Set next Entry in same hash-bucket.- Specified by:
setEntryNext
in classAbstractHashTable<AbstractWeakHashTable.WEntry<K,V>,K,V>
-
allocEntries
protected AbstractWeakHashTable.WEntry<K,V>[] allocEntries(int n)
Description copied from class:AbstractHashTable
Allocate Entry[n].- Specified by:
allocEntries
in classAbstractHashTable<AbstractWeakHashTable.WEntry<K,V>,K,V>
-
getValueIfMatching
protected V getValueIfMatching(AbstractWeakHashTable.WEntry<K,V> node, Object key)
-
get
public V get(Object key, V defaultValue)
Description copied from class:AbstractHashTable
Find value for given key. Return defaultValue if not found.- Overrides:
get
in classAbstractHashTable<AbstractWeakHashTable.WEntry<K,V>,K,V>
-
hash
public int hash(Object key)
Description copied from class:AbstractHashTable
Calculate hash code of a key.- Overrides:
hash
in classAbstractHashTable<AbstractWeakHashTable.WEntry<K,V>,K,V>
-
makeEntry
protected AbstractWeakHashTable.WEntry<K,V> makeEntry(K key, int hash, V value)
Description copied from class:AbstractHashTable
Allocate a new node in the hash table.- Specified by:
makeEntry
in classAbstractHashTable<AbstractWeakHashTable.WEntry<K,V>,K,V>
-
cleanup
protected void cleanup()
-
-