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