public class CompactHashSet<E> extends AbstractSet<E>
Modifier and Type | Field and Description |
---|---|
protected static Object |
deletedObject
When an object is deleted this object is put into the hashtable
in its place, so that other objects with the same key
(collisions) further down the hashtable are not lost after we
delete an object in the collision chain.
|
protected int |
elements |
protected int |
freecells
This is the number of empty (null) cells.
|
protected static int |
INITIAL_SIZE |
protected static double |
LOAD_FACTOR |
protected int |
modCount |
protected static Object |
nullObject
This object is used to represent null, should clients add that to the set.
|
protected E[] |
objects |
Constructor and Description |
---|
CompactHashSet()
Constructs a new, empty set.
|
CompactHashSet(Collection<E> c)
Constructs a new set containing the elements in the specified
collection.
|
CompactHashSet(int size)
Constructs a new, empty set.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Object o)
Adds the specified element to this set if it is not already
present.
|
void |
clear()
Removes all of the elements from this set.
|
boolean |
contains(Object o)
Returns true if this set contains the specified element.
|
void |
dump()
INTERNAL: Used for debugging only.
|
boolean |
isEmpty()
Returns true if this set contains no elements.
|
Iterator<E> |
iterator()
Returns an iterator over the elements in this set.
|
protected void |
rehash()
INTERNAL: Figures out correct size for rehashed set, then does
the rehash.
|
protected void |
rehash(int newCapacity)
INTERNAL: Rehashes the hashset to a bigger size.
|
boolean |
remove(Object o)
Removes the specified element from the set.
|
int |
size()
Returns the number of elements in this set (its cardinality).
|
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
equals, hashCode, removeAll
addAll, containsAll, retainAll, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, containsAll, retainAll, spliterator
parallelStream, removeIf, stream
protected static final int INITIAL_SIZE
protected static final double LOAD_FACTOR
protected static final Object nullObject
protected static final Object deletedObject
protected int elements
protected int freecells
protected E[] objects
protected int modCount
public CompactHashSet()
public CompactHashSet(int size)
public CompactHashSet(Collection<E> c)
c
- the collection whose elements are to be placed into this set.public Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in interface Set<E>
iterator
in class AbstractCollection<E>
ConcurrentModificationException
public int size()
size
in interface Collection<E>
size
in interface Set<E>
size
in class AbstractCollection<E>
public boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in interface Set<E>
isEmpty
in class AbstractCollection<E>
public boolean contains(Object o)
contains
in interface Collection<E>
contains
in interface Set<E>
contains
in class AbstractCollection<E>
o
- element whose presence in this set is to be tested.public boolean add(Object o)
add
in interface Collection<E>
add
in interface Set<E>
add
in class AbstractCollection<E>
o
- element to be added to this set.public boolean remove(Object o)
remove
in interface Collection<E>
remove
in interface Set<E>
remove
in class AbstractCollection<E>
public void clear()
clear
in interface Collection<E>
clear
in interface Set<E>
clear
in class AbstractCollection<E>
public Object[] toArray()
toArray
in interface Collection<E>
toArray
in interface Set<E>
toArray
in class AbstractCollection<E>
public <T> T[] toArray(T[] a)
toArray
in interface Collection<E>
toArray
in interface Set<E>
toArray
in class AbstractCollection<E>
public void dump()
protected void rehash()
protected void rehash(int newCapacity)