Package ghidra.pcodeCPort.utils
Class WeakHashMap2<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- ghidra.pcodeCPort.utils.WeakHashMap2<K,V>
-
- All Implemented Interfaces:
java.util.Map<K,V>
public class WeakHashMap2<K,V> extends java.util.AbstractMap<K,V>
A hashtable-basedMap
implementation with weak values.This implementation uses two maps internally, which nearly doubles the memory requirements over a traditional map.
-
-
Constructor Summary
Constructors Constructor Description WeakHashMap2()
Constructs a new, emptyWeakHashMap2
with the default initial capacity and the default load factor, which is0.75
.WeakHashMap2(int initialCapacity)
Constructs a new, emptyWeakHashMap2
with the given initial capacity and the default load factor, which is0.75
.WeakHashMap2(int initialCapacity, float loadFactor)
Constructs a new, emptyWeakHashMap2
with the given initial capacity and the given load factor.WeakHashMap2(java.util.Map<K,V> t)
Constructs a newWeakHashMap2
with the same mappings as the specified Map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all mappings from this map.boolean
containsKey(java.lang.Object key)
Returnstrue
if this map contains a mapping for the specified key.java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
Returns aSet
view of the mappings in this map.V
get(java.lang.Object key)
Returns the value to which this map maps the specifiedkey
.boolean
isEmpty()
Returnstrue
if this map contains no key-value mappings.V
put(K key, V value)
Updates this map so that the givenkey
maps to the givenvalue
.V
remove(java.lang.Object key)
Removes the mapping for the givenkey
from this map, if present.K
reverseGet(V value)
int
size()
Returns the number of key-value mappings in this map.-
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, keySet, putAll, toString, values
-
-
-
-
Constructor Detail
-
WeakHashMap2
public WeakHashMap2(int initialCapacity, float loadFactor)
Constructs a new, emptyWeakHashMap2
with the given initial capacity and the given load factor.- Parameters:
initialCapacity
- The initial capacity of theWeakHashMap2
loadFactor
- The load factor of theWeakHashMap2
- Throws:
java.lang.IllegalArgumentException
- If the initial capacity is less than zero, or if the load factor is nonpositive
-
WeakHashMap2
public WeakHashMap2(int initialCapacity)
Constructs a new, emptyWeakHashMap2
with the given initial capacity and the default load factor, which is0.75
.- Parameters:
initialCapacity
- The initial capacity of theWeakHashMap2
- Throws:
java.lang.IllegalArgumentException
- If the initial capacity is less than zero
-
WeakHashMap2
public WeakHashMap2()
Constructs a new, emptyWeakHashMap2
with the default initial capacity and the default load factor, which is0.75
.
-
WeakHashMap2
public WeakHashMap2(java.util.Map<K,V> t)
Constructs a newWeakHashMap2
with the same mappings as the specified Map. TheWeakHashMap2
is created with an initial capacity of twice the number of mappings in the specified map or 11 (whichever is greater), and a default load factor, which is 0.75.- Parameters:
t
- the map whose mappings are to be placed in this map.- Since:
- 1.3
-
-
Method Detail
-
size
public int size()
Returns the number of key-value mappings in this map. Note: In contrast with most implementations of theMap
interface, the time required by this operation is linear in the size of the map.
-
isEmpty
public boolean isEmpty()
Returnstrue
if this map contains no key-value mappings.
-
containsKey
public boolean containsKey(java.lang.Object key)
Returnstrue
if this map contains a mapping for the specified key.
-
get
public V get(java.lang.Object key)
Returns the value to which this map maps the specifiedkey
. If this map does not contain a value for this key, then returnnull
.
-
put
public V put(K key, V value)
Updates this map so that the givenkey
maps to the givenvalue
. If the map previously contained a mapping forkey
then that mapping is replaced and the previous value is returned.- Specified by:
put
in interfacejava.util.Map<K,V>
- Overrides:
put
in classjava.util.AbstractMap<K,V>
- Parameters:
key
- The key that is to be mapped to the givenvalue
value
- The value to which the givenkey
is to be mapped- Returns:
- The previous value to which this key was mapped, or
null
if if there was no mapping for the key
-
remove
public V remove(java.lang.Object key)
Removes the mapping for the givenkey
from this map, if present.
-
clear
public void clear()
Removes all mappings from this map.
-
-