Package org.jboss.msc.service
Class IdentityHashSet<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- org.jboss.msc.service.IdentityHashSet<E>
-
- Type Parameters:
E- the element type
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.Set<E>
class IdentityHashSet<E> extends java.util.AbstractSet<E> implements java.util.Set<E>, java.lang.Cloneable, java.io.SerializableAn identity based hash set. A number of properties apply to this set. It compares only using object identity, it supports null entries, it allocates little more than a single object array, and it can be copied quickly. If the copy-ctor is passed another IdentityHashSet, or clone is called on this set, the shallow copy can be performed using little more than a single array copy. 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 classIdentityHashSet.IdentityHashSetIterator
-
Field Summary
Fields Modifier and Type Field Description private static intDEFAULT_CAPACITYSame default as HashMap, must be a power of 2private static floatDEFAULT_LOAD_FACTOR67%, just like IdentityHashMapprivate 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 java.lang.Object[]tableThe open-addressed tableprivate intthresholdThe next resize
-
Constructor Summary
Constructors Constructor Description IdentityHashSet()IdentityHashSet(int initialCapacity)IdentityHashSet(int initialCapacity, float loadFactor)IdentityHashSet(java.util.Set<? extends E> set)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E entry)booleanaddAll(java.util.Collection<? extends E> collection)voidclear()IdentityHashSet<E>clone()booleancontains(java.lang.Object entry)private static inthash(java.lang.Object o)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 entry)private voidreadObject(java.io.ObjectInputStream s)private voidrelocate(int start)booleanremove(java.lang.Object o)private voidresize(int from)intsize()E[]toArray(E[] target, int offs, int len)Warning: this will crap out if the set contains anull.<T> T[]toScatteredArray(T[] dummy)Advanced method that returns a copy of the internal table.private voidwriteObject(java.io.ObjectOutputStream s)-
Methods inherited from class java.util.AbstractCollection
containsAll, retainAll, toArray, toArray, toString
-
-
-
-
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
67%, just like IdentityHashMap- See Also:
- Constant Field Values
-
table
private transient java.lang.Object[] 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
-
-
Constructor Detail
-
IdentityHashSet
public IdentityHashSet(int initialCapacity, float loadFactor)
-
IdentityHashSet
public IdentityHashSet(java.util.Set<? extends E> set)
-
IdentityHashSet
public IdentityHashSet(int initialCapacity)
-
IdentityHashSet
public IdentityHashSet()
-
-
Method Detail
-
init
private void init(int initialCapacity, float loadFactor)
-
hash
private static int hash(java.lang.Object o)
-
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 entry)
-
add
public boolean add(E entry)
-
resize
private void resize(int from)
-
addAll
public boolean addAll(java.util.Collection<? extends E> collection)
-
remove
public boolean remove(java.lang.Object o)
-
relocate
private void relocate(int start)
-
clear
public void clear()
-
clone
public IdentityHashSet<E> clone()
- Overrides:
clonein classjava.lang.Object
-
toScatteredArray
public <T> T[] toScatteredArray(T[] dummy)
Advanced method that returns a copy of the internal table. The resulting array will contain nulls at random places that must be skipped. In addition, it will not operate correctly if a null was inserted into the set. Use at your own risk....- Parameters:
dummy- the input array- Returns:
- an array containing elements in this set along with randomly placed nulls,
-
toArray
public E[] toArray(E[] target, int offs, int len)
Warning: this will crap out if the set contains anull.- Parameters:
target- the target to write tooffs- the offset into the targetlen- the length to write- Returns:
- the target array
-
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 entry)
-
writeObject
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException- Throws:
java.io.IOException
-
-