Package com.biglybt.core.util
Class LightHashMap<S,T>
java.lang.Object
java.util.AbstractMap<S,T>
com.biglybt.core.util.LightHashMap<S,T>
- Direct Known Subclasses:
JSONObject
,LightHashMapEx
A lighter (on memory) hash map
Advantages over HashMap:
Advantages over HashMap:
- Lower memory footprint
- Everything is stored in a single array, this might improve cache performance (not verified)
- Read-only operations on Key and Value iterators should be concurrency-safe (Entry iterators are not) but they might return null values unexpectedly under concurrent modification (not verified)
- removal is implemented with thombstone-keys, this can significantly increase the lookup time if many values are removed. Use compactify() for scrubbing
- entry set iterators and thus transfers to other maps are slower than comparable implementations
- the map does not store hashcodes and relies on either the key-objects themselves caching them (such as strings) or a fast computation of hashcodes
- concurrent modification detection is not as fail-fast as HashMap as no modification counter is used and only structural differences are noted
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
private class
private class
private class
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLightHashMap
(int initialCapacity) LightHashMap
(int initialCapacity, float loadFactor) LightHashMap
(Map m) -
Method Summary
Modifier and TypeMethodDescriptionprivate Object
private void
adjustCapacity
(int newSize) int
capacity()
private void
checkCapacity
(int n) void
clear()
clone()
void
compactify
(float compactingLoadFactor) will shrink the internal storage size to the least possible amount, should be used after removing many entries for exampleboolean
containsKey
(Object key) boolean
containsValue
(Object value) entrySet()
private int
private boolean
keySet()
static void
private int
nonModifyingFindIndex
(Object keyToFind) void
private Object
removeForIndex
(int idx) (package private) static void
test()
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, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
THOMBSTONE
-
NULLKEY
-
DEFAULT_LOAD_FACTOR
private static final float DEFAULT_LOAD_FACTOR- See Also:
-
DEFAULT_CAPACITY
private static final int DEFAULT_CAPACITY- See Also:
-
loadFactor
final float loadFactor -
size
int size -
data
Object[] data
-
-
Constructor Details
-
LightHashMap
public LightHashMap() -
LightHashMap
public LightHashMap(int initialCapacity) -
LightHashMap
-
LightHashMap
public LightHashMap(int initialCapacity, float loadFactor)
-
-
Method Details
-
clone
- Overrides:
clone
in classAbstractMap<S,
T>
-
entrySet
-
put
-
putAll
-
keySet
-
values
-
capacity
public int capacity() -
get
-
add
-
remove
-
removeForIndex
-
clear
public void clear() -
containsKey
- Specified by:
containsKey
in interfaceMap<S,
T> - Overrides:
containsKey
in classAbstractMap<S,
T>
-
containsValue
- Specified by:
containsValue
in interfaceMap<S,
T> - Overrides:
containsValue
in classAbstractMap<S,
T>
-
keysEqual
-
findIndex
-
nonModifyingFindIndex
-
checkCapacity
private void checkCapacity(int n) -
compactify
public void compactify(float compactingLoadFactor) will shrink the internal storage size to the least possible amount, should be used after removing many entries for example- Parameters:
compactingLoadFactor
- load factor for the compacting operation. Use 0f to compact with the load factor specified during instantiation. Use negative values of the desired load factors to compact only when it would reduce the storage size.
-
adjustCapacity
private void adjustCapacity(int newSize) -
test
static void test() -
main
-