Class LightHashSet
java.lang.Object
java.util.AbstractCollection
java.util.AbstractSet
com.biglybt.core.util.LightHashSet
- All Implemented Interfaces:
Cloneable, Iterable, Collection, Set
A lighter (on memory) hash set
Advantages over HashSet:
Advantages over HashSet:
- Lower memory footprint
- Everything is stored in a single array, this might improve cache performance (not verified)
- Read-only operations on iterators should be concurrency-safe 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
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLightHashSet(int initialCapacity) LightHashSet(int initialCapacity, float loadFactor) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection c) private booleanaddInternal(Object key, boolean bulkAdd) private voidadjustCapacity(int newSize) intcapacity()private voidcheckCapacity(int n) voidclear()clone()voidcompactify(float compactingLoadFactor) will shrink the internal storage size to the least possible amount, should be used after removing many entries for examplebooleanprivate intFetches an element which does equal() the provided object but is not necessarily the same objectiterator()private booleanstatic voidprivate intnonModifyingFindIndex(Object keyToFind) booleanprivate voidremoveForIndex(int idx) intsize()(package private) static voidtest()Methods inherited from class AbstractSet
equals, hashCode, removeAllMethods inherited from class AbstractCollection
containsAll, isEmpty, retainAll, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface Set
containsAll, isEmpty, retainAll, spliterator, toArray, toArray
-
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
-
LightHashSet
public LightHashSet() -
LightHashSet
public LightHashSet(int initialCapacity) -
LightHashSet
-
LightHashSet
public LightHashSet(int initialCapacity, float loadFactor)
-
-
Method Details
-
clone
-
iterator
- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- Specified by:
iteratorin interfaceSet- Specified by:
iteratorin classAbstractCollection
-
add
- Specified by:
addin interfaceCollection- Specified by:
addin interfaceSet- Overrides:
addin classAbstractCollection
-
size
public int size()- Specified by:
sizein interfaceCollection- Specified by:
sizein interfaceSet- Specified by:
sizein classAbstractCollection
-
addAll
- Specified by:
addAllin interfaceCollection- Specified by:
addAllin interfaceSet- Overrides:
addAllin classAbstractCollection
-
capacity
public int capacity() -
get
-
addInternal
-
remove
- Specified by:
removein interfaceCollection- Specified by:
removein interfaceSet- Overrides:
removein classAbstractCollection
-
removeForIndex
private void removeForIndex(int idx) -
clear
public void clear()- Specified by:
clearin interfaceCollection- Specified by:
clearin interfaceSet- Overrides:
clearin classAbstractCollection
-
contains
- Specified by:
containsin interfaceCollection- Specified by:
containsin interfaceSet- Overrides:
containsin classAbstractCollection
-
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
-