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 int
Same default as HashMap, must be a power of 2private static final float
50%private int
Accumulated hash codeprivate final float
The user defined load factor which defines when to resizeprivate static final int
MAX_INT - 1private int
Counter used to detect changes made outside of an iteratorprivate static final long
Serialization IDprivate int
The current number of key-value pairsprivate E[]
The open-addressed tableprivate int
The next resize -
Constructor Summary
ConstructorsConstructorDescriptionFastCopyHashSet
(int initialCapacity) FastCopyHashSet
(int initialCapacity, float loadFactor) FastCopyHashSet
(Set<? extends E> set) -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> set) void
clear()
clone()
boolean
boolean
containsAll
(Collection<?> c) boolean
Object[]
int
hashCode()
private static int
index
(int hashCode, int length) private void
init
(int initialCapacity, float loadFactor) boolean
isEmpty()
iterator()
private int
nextIndex
(int index, int length) void
private void
putForCreate
(E key) private void
private void
relocate
(int start) boolean
private void
resize
(int from) int
size()
private void
Methods inherited from class java.util.AbstractSet
removeAll
Methods inherited from class java.util.AbstractCollection
retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceSet<E>
- Specified by:
size
in classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceSet<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceSet<E>
- Overrides:
contains
in classAbstractCollection<E>
-
add
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceSet<E>
- Overrides:
add
in classAbstractCollection<E>
-
resize
private void resize(int from) -
addAll
- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceSet<E>
- Overrides:
addAll
in classAbstractCollection<E>
-
remove
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in classAbstractCollection<E>
-
relocate
private void relocate(int start) -
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceSet<E>
- Overrides:
clear
in classAbstractCollection<E>
-
clone
-
iterator
-
printDebugStats
public void printDebugStats() -
readObject
- Throws:
IOException
ClassNotFoundException
-
putForCreate
-
writeObject
- Throws:
IOException
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
- Overrides:
containsAll
in classAbstractCollection<E>
-
equals
- Specified by:
equals
in interfaceCollection<E>
- Specified by:
equals
in interfaceSet<E>
- Overrides:
equals
in classAbstractSet<E>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<E>
- Specified by:
hashCode
in interfaceSet<E>
- Overrides:
hashCode
in classAbstractSet<E>
-
getRawArray
-