Package org.jboss.modules
Class FastCopyHashSet<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
org.jboss.modules.FastCopyHashSet<E>
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<E>,Collection<E>,Set<E>
A HashSet that is optimized for fast shallow copies. If the copy-ctor is
passed another FastCopyHashSet, or clone is called on this set, the shallow
copy can be performed using little more than a single array copy. In order to
accomplish this, immutable objects must be used internally, so update
operations result in slightly more object churn than
HashSet.
Note: It is very important to use a smaller load factor than you normally
would for HashSet, since the implementation is open-addressed with linear
probing. With a 50% load-factor a get is expected to return in only 2 probes.
However, a 90% load-factor is expected to return in around 50 probes.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intSame default as HashMap, must be a power of 2private static final float50%private intAccumulated hash codeprivate final floatThe user defined load factor which defines when to resizeprivate static final intMAX_INT - 1private intCounter used to detect changes made outside of an iteratorprivate static final longSerialization IDprivate intThe current number of key-value pairsprivate E[]The open-addressed tableprivate intThe next resize -
Constructor Summary
ConstructorsConstructorDescriptionFastCopyHashSet(int initialCapacity) FastCopyHashSet(int initialCapacity, float loadFactor) FastCopyHashSet(Set<? extends E> set) -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends E> set) voidclear()clone()booleanbooleancontainsAll(Collection<?> c) booleanObject[]inthashCode()private static intindex(int hashCode, int length) private voidinit(int initialCapacity, float loadFactor) booleanisEmpty()iterator()private intnextIndex(int index, int length) voidprivate voidputForCreate(E key) private voidprivate voidrelocate(int start) booleanprivate voidresize(int from) intsize()private voidMethods inherited from class java.util.AbstractSet
removeAllMethods inherited from class java.util.AbstractCollection
retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerialization ID- See Also:
-
DEFAULT_CAPACITY
private static final int DEFAULT_CAPACITYSame default as HashMap, must be a power of 2- See Also:
-
MAXIMUM_CAPACITY
private static final int MAXIMUM_CAPACITYMAX_INT - 1- See Also:
-
DEFAULT_LOAD_FACTOR
private static final float DEFAULT_LOAD_FACTOR50%- See Also:
-
table
The open-addressed table -
size
private transient int sizeThe current number of key-value pairs -
threshold
private transient int thresholdThe next resize -
loadFactor
private final float loadFactorThe user defined load factor which defines when to resize -
modCount
private transient int modCountCounter used to detect changes made outside of an iterator -
hashCode
private transient int hashCodeAccumulated hash code
-
-
Constructor Details
-
FastCopyHashSet
FastCopyHashSet(int initialCapacity, float loadFactor) -
FastCopyHashSet
-
FastCopyHashSet
FastCopyHashSet(int initialCapacity) -
FastCopyHashSet
FastCopyHashSet()
-
-
Method Details
-
init
private void init(int initialCapacity, float loadFactor) -
nextIndex
private int nextIndex(int index, int length) -
index
private static int index(int hashCode, int length) -
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
contains
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
resize
private void resize(int from) -
addAll
- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceSet<E>- Overrides:
addAllin classAbstractCollection<E>
-
remove
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
relocate
private void relocate(int start) -
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
clone
-
iterator
-
printDebugStats
public void printDebugStats() -
readObject
- Throws:
IOExceptionClassNotFoundException
-
putForCreate
-
writeObject
- Throws:
IOException
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>- Overrides:
containsAllin classAbstractCollection<E>
-
equals
- Specified by:
equalsin interfaceCollection<E>- Specified by:
equalsin interfaceSet<E>- Overrides:
equalsin classAbstractSet<E>
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<E>- Specified by:
hashCodein interfaceSet<E>- Overrides:
hashCodein classAbstractSet<E>
-
getRawArray
-