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 |
| Modifier and Type | Field and Description |
|---|---|
| private static final int | DEFAULT_CAPACITY
Same default as HashMap, must be a power of 2 |
| private static final float | |
| private transient int | hashCode
Accumulated hash code |
| private final float | loadFactor
The user defined load factor which defines when to resize |
| private static final int | MAXIMUM_CAPACITY
MAX_INT - 1 |
| private transient int | modCount
Counter used to detect changes made outside of an iterator |
| private static final long | serialVersionUID
Serialization ID |
| private transient int | size
The current number of key-value pairs |
| private transient E[] | table
The open-addressed table |
| private transient int | threshold
The next resize |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv | |
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(E
element to be added to this set key)Overrides java. Implements java. |
| public boolean | addAll(Collection<? extends E>
collection containing elements to be added to this set set)Overrides java. Implements java. |
| public void | clear()
Overrides java. Implements java. |
| public FastCopyHashSet | |
| public boolean | contains(Object
element whose presence in this set is to be tested key)Overrides java. Implements java. true if this set contains the specified element.
|
| public boolean | containsAll(final Collection<?>
collection to be checked for containment in this set c)Overrides java. Implements java. true if this set contains all of the elements of the
specified collection.
|
| public boolean | equals(final Object
object to be compared for equality with this set o)Overrides java. Implements java. |
| public Object[] | |
| public int | hashCode()
Overrides java. Implements java. |
| private static int | |
| private void | |
| public boolean | isEmpty()
Overrides java. Implements java. true if this set contains no elements.
|
| public Iterator | iterator()
Implements abstract java. Implements java. |
| private int | |
| public void | |
| private void | |
| private void | |
| private void | |
| public boolean | remove(Object
object to be removed from this set, if present key)Overrides java. Implements java. |
| private void | |
| public int | size()
Implements abstract java. Implements java. |
| private void |
| DEFAULT_CAPACITY | back to summary |
|---|---|
| private static final int DEFAULT_CAPACITY Same default as HashMap, must be a power of 2 | |
| DEFAULT_LOAD_FACTOR | back to summary |
|---|---|
| private static final float DEFAULT_LOAD_FACTOR 50% | |
| hashCode | back to summary |
|---|---|
| private transient int hashCode Accumulated hash code | |
| loadFactor | back to summary |
|---|---|
| private final float loadFactor The user defined load factor which defines when to resize | |
| MAXIMUM_CAPACITY | back to summary |
|---|---|
| private static final int MAXIMUM_CAPACITY MAX_INT - 1 | |
| modCount | back to summary |
|---|---|
| private transient int modCount Counter used to detect changes made outside of an iterator | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization ID | |
| size | back to summary |
|---|---|
| private transient int size The current number of key-value pairs | |
| table | back to summary |
|---|---|
| private transient E[] table The open-addressed table | |
| threshold | back to summary |
|---|---|
| private transient int threshold The next resize | |
| FastCopyHashSet | back to summary |
|---|---|
| pack-priv FastCopyHashSet(int initialCapacity, float loadFactor) | |
| FastCopyHashSet | back to summary |
|---|---|
| pack-priv FastCopyHashSet(Set<? extends E> set) | |
| FastCopyHashSet | back to summary |
|---|---|
| pack-priv FastCopyHashSet(int initialCapacity) | |
| FastCopyHashSet | back to summary |
|---|---|
| pack-priv FastCopyHashSet() | |
| add | back to summary |
|---|---|
| public boolean add(E key) Overrides java. Implements java. Doc from java. Adds the specified element to this set if it is not already present
(optional operation). More formally, adds the specified element
The stipulation above does not imply that sets must accept all
elements; sets may refuse to add any particular element, including
| |
| addAll | back to summary |
|---|---|
| public boolean addAll(Collection<? extends E> set) Overrides java. Implements java. Doc from java. Adds all of the elements in the specified collection to this set if
they're not already present (optional operation). If the specified
collection is also a set, the
| |
| clear | back to summary |
|---|---|
| public void clear() Overrides java. Implements java. Doc from java. Removes all of the elements from this set (optional operation). The set will be empty after this call returns. | |
| clone | back to summary |
|---|---|
| public FastCopyHashSet Overrides java. Doc from java. Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by
| |
| contains | back to summary |
|---|---|
| public boolean contains(Object key) Overrides java. Implements java. Doc from java. Returns
| |
| containsAll | back to summary |
|---|---|
| public boolean containsAll(final Collection<?> c) Overrides java. Implements java. Doc from java. Returns
| |
| equals | back to summary |
|---|---|
| public boolean equals(final Object o) Overrides java. Implements java. Doc from java. Compares the specified object with this set for equality. Returns
| |
| getRawArray | back to summary |
|---|---|
| public Object[] getRawArray() | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements java. Doc from java. Returns the hash code value for this set. The hash code of a set is
defined to be the sum of the hash codes of the elements in the set,
where the hash code of a
| |
| index | back to summary |
|---|---|
| private static int index(int hashCode, int length) | |
| init | back to summary |
|---|---|
private void init(int initialCapacity, float loadFactor)
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Overrides java. Implements java. Doc from java. Returns
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements abstract java. Implements java. Doc from java. Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).
| |
| nextIndex | back to summary |
|---|---|
| private int nextIndex(int index, int length) | |
| printDebugStats | back to summary |
|---|---|
| public void printDebugStats() | |
| putForCreate | back to summary |
|---|---|
private void putForCreate(E key)
| |
| readObject | back to summary |
|---|---|
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
| |
| relocate | back to summary |
|---|---|
| private void relocate(int start) | |
| remove | back to summary |
|---|---|
| public boolean remove(Object key) Overrides java. Implements java. Doc from java. Removes the specified element from this set if it is present
(optional operation). More formally, removes an element
| |
| resize | back to summary |
|---|---|
private void resize(int from)
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this set (its cardinality). If this
set contains more than
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException | |
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private int | |
| private boolean | |
| private int | |
| private E[] |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public E | |
| public void | remove()
Overrides default java. |
| current | back to summary |
|---|---|
| private int current | |
| expectedCount | back to summary |
|---|---|
| private int expectedCount | |
| hasNext | back to summary |
|---|---|
| private boolean hasNext | |
| next | back to summary |
|---|---|
| private int next | |
| table | back to summary |
|---|---|
| private E[] table | |
| KeyIterator | back to summary |
|---|---|
| private KeyIterator() | |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| next | back to summary |
|---|---|
| public E next() Implements java. Doc from java. Returns the next element in the iteration.
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Doc from java. Removes from the underlying collection the last element returned
by this iterator (optional operation). This method can be called
only once per call to The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.
The behavior of an iterator is unspecified if this method is called
after a call to the
| |