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.Serializable
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 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 class
FastCopyHashSet.KeyIterator
-
Field Summary
Fields Modifier and Type Field Description private static int
DEFAULT_CAPACITY
Same default as HashMap, must be a power of 2private static float
DEFAULT_LOAD_FACTOR
50%private int
hashCode
Accumulated hash codeprivate float
loadFactor
The user defined load factor which defines when to resizeprivate static int
MAXIMUM_CAPACITY
MAX_INT - 1private int
modCount
Counter used to detect changes made outside of an iteratorprivate static long
serialVersionUID
Serialization IDprivate int
size
The current number of key-value pairsprivate E[]
table
The open-addressed tableprivate int
threshold
The 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 boolean
add(E key)
boolean
addAll(java.util.Collection<? extends E> set)
void
clear()
FastCopyHashSet<E>
clone()
boolean
contains(java.lang.Object key)
boolean
containsAll(java.util.Collection<?> c)
boolean
equals(java.lang.Object o)
java.lang.Object[]
getRawArray()
int
hashCode()
private static int
index(int hashCode, int length)
private void
init(int initialCapacity, float loadFactor)
boolean
isEmpty()
java.util.Iterator<E>
iterator()
private int
nextIndex(int index, int length)
void
printDebugStats()
private void
putForCreate(E key)
private void
readObject(java.io.ObjectInputStream s)
private void
relocate(int start)
boolean
remove(java.lang.Object key)
private void
resize(int from)
int
size()
private void
writeObject(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:
clone
in 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.IOException
java.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()
-
-