Package net.ontopia.utils
Class CompactHashSet<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
net.ontopia.utils.CompactHashSet<E>
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Set<E>
- Direct Known Subclasses:
CompactIdentityHashSet,SynchronizedCompactHashSet,TreeWidget.UniversalSet,UniqueSet
INTERNAL: Implements the Set interface more compactly than
java.util.HashSet by using a closed hashtable.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final ObjectWhen 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 intprotected intThis is the number of empty (null) cells.protected static final intprotected static final doubleprotected intprotected static final ObjectThis object is used to represent null, should clients add that to the set.protected E[] -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new, empty set.CompactHashSet(int size) Constructs a new, empty set.Constructs a new set containing the elements in the specified collection. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the specified element to this set if it is not already present.voidclear()Removes all of the elements from this set.booleanReturns true if this set contains the specified element.voiddump()INTERNAL: Used for debugging only.booleanisEmpty()Returns true if this set contains no elements.iterator()Returns an iterator over the elements in this set.protected voidrehash()INTERNAL: Figures out correct size for rehashed set, then does the rehash.protected voidrehash(int newCapacity) INTERNAL: Rehashes the hashset to a bigger size.booleanRemoves the specified element from the set.intsize()Returns the number of elements in this set (its cardinality).Object[]toArray()<T> T[]toArray(T[] a) Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAllMethods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
addAll, containsAll, retainAll, spliterator
-
Field Details
-
INITIAL_SIZE
protected static final int INITIAL_SIZE- See Also:
-
LOAD_FACTOR
protected static final double LOAD_FACTOR- See Also:
-
nullObject
This object is used to represent null, should clients add that to the set. -
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. -
elements
protected int elements -
freecells
protected int freecellsThis is the number of empty (null) cells. It's not necessarily the same as objects.length - elements, because some cells may contain deletedObject. -
objects
-
modCount
protected int modCount
-
-
Constructor Details
-
CompactHashSet
public CompactHashSet()Constructs a new, empty set. -
CompactHashSet
public CompactHashSet(int size) Constructs a new, empty set. -
CompactHashSet
Constructs a new set containing the elements in the specified collection.- Parameters:
c- the collection whose elements are to be placed into this set.
-
-
Method Details
-
iterator
Returns an iterator over the elements in this set. The elements are returned in no particular order. -
size
public int size()Returns the number of elements in this set (its cardinality).- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()Returns true if this set contains no elements.- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
contains
Returns true if this set contains the specified element.- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>- Parameters:
o- element whose presence in this set is to be tested.- Returns:
- true if this set contains the specified element.
-
add
Adds the specified element to this set if it is not already present.- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>- Parameters:
o- element to be added to this set.- Returns:
- true if the set did not already contain the specified element.
-
remove
Removes the specified element from the set.- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
clear
public void clear()Removes all of the elements from this set.- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
toArray
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin classAbstractCollection<E>
-
dump
public void dump()INTERNAL: Used for debugging only. -
rehash
protected void rehash()INTERNAL: Figures out correct size for rehashed set, then does the rehash. -
rehash
protected void rehash(int newCapacity) INTERNAL: Rehashes the hashset to a bigger size.
-