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:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.Set<E>
class FastCopyHashSet<E> extends java.util.AbstractSet<E> implements java.util.Set<E>, java.lang.Cloneable, java.io.SerializableA 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 thanHashSet. 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 Modifier and Type Class Description private classFastCopyHashSet.KeyIterator
-
Field Summary
Fields Modifier and Type Field Description private static intDEFAULT_CAPACITYSame default as HashMap, must be a power of 2private static floatDEFAULT_LOAD_FACTOR50%private inthashCodeAccumulated hash codeprivate floatloadFactorThe user defined load factor which defines when to resizeprivate static intMAXIMUM_CAPACITYMAX_INT - 1private intmodCountCounter used to detect changes made outside of an iteratorprivate static longserialVersionUIDSerialization IDprivate intsizeThe current number of key-value pairsprivate E[]tableThe open-addressed tableprivate intthresholdThe next resize
-
Constructor Summary
Constructors Constructor Description FastCopyHashSet()FastCopyHashSet(int initialCapacity)FastCopyHashSet(int initialCapacity, float loadFactor)FastCopyHashSet(java.util.Set<? extends E> set)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E key)booleanaddAll(java.util.Collection<? extends E> set)voidclear()FastCopyHashSet<E>clone()booleancontains(java.lang.Object key)booleancontainsAll(java.util.Collection<?> c)booleanequals(java.lang.Object o)java.lang.Object[]getRawArray()inthashCode()private static intindex(int hashCode, int length)private voidinit(int initialCapacity, float loadFactor)booleanisEmpty()java.util.Iterator<E>iterator()private intnextIndex(int index, int length)voidprintDebugStats()private voidputForCreate(E key)private voidreadObject(java.io.ObjectInputStream s)private voidrelocate(int start)booleanremove(java.lang.Object key)private voidresize(int from)intsize()private voidwriteObject(java.io.ObjectOutputStream s)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serialization ID- See Also:
- Constant Field Values
-
DEFAULT_CAPACITY
private static final int DEFAULT_CAPACITY
Same default as HashMap, must be a power of 2- See Also:
- Constant Field Values
-
MAXIMUM_CAPACITY
private static final int MAXIMUM_CAPACITY
MAX_INT - 1- See Also:
- Constant Field Values
-
DEFAULT_LOAD_FACTOR
private static final float DEFAULT_LOAD_FACTOR
50%- See Also:
- Constant Field Values
-
table
private transient E[] table
The open-addressed table
-
size
private transient int size
The current number of key-value pairs
-
threshold
private transient int threshold
The next resize
-
loadFactor
private final float loadFactor
The user defined load factor which defines when to resize
-
modCount
private transient int modCount
Counter used to detect changes made outside of an iterator
-
hashCode
private transient int hashCode
Accumulated hash code
-
-
Constructor Detail
-
FastCopyHashSet
FastCopyHashSet(int initialCapacity, float loadFactor)
-
FastCopyHashSet
FastCopyHashSet(java.util.Set<? extends E> set)
-
FastCopyHashSet
FastCopyHashSet(int initialCapacity)
-
FastCopyHashSet
FastCopyHashSet()
-
-
Method Detail
-
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()
-
isEmpty
public boolean isEmpty()
-
contains
public boolean contains(java.lang.Object key)
-
add
public boolean add(E key)
-
resize
private void resize(int from)
-
addAll
public boolean addAll(java.util.Collection<? extends E> set)
-
remove
public boolean remove(java.lang.Object key)
-
relocate
private void relocate(int start)
-
clear
public void clear()
-
clone
public FastCopyHashSet<E> clone()
- Overrides:
clonein classjava.lang.Object
-
iterator
public java.util.Iterator<E> iterator()
-
printDebugStats
public void printDebugStats()
-
readObject
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, java.lang.ClassNotFoundException- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
putForCreate
private void putForCreate(E key)
-
writeObject
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException- Throws:
java.io.IOException
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
equals
public boolean equals(java.lang.Object o)
-
hashCode
public int hashCode()
-
getRawArray
public java.lang.Object[] getRawArray()
-
-