java.lang.Object
org.apache.jena.mem.collection.FastHashBase<K>
org.apache.jena.mem.collection.FastHashSet<K>
- Type Parameters:
K- the element type
- All Implemented Interfaces:
Iterable<K>,JenaMapSetCommon<K>,JenaSet<K>,JenaSetHashOptimized<K>,JenaSetIndexed<K>,Sized
- Direct Known Subclasses:
FastHashedTripleBunch,TripleSet,TripleSet
Hash set specialization built on top of
FastHashBase.
Grows on demand but never shrinks, does not guarantee iteration order,
does not allow null elements, and is not thread-safe.
Optimized for fast add / containsKey / stream /
iterate operations. Removal is somewhat slower than in
HashSet because of the back-shifting performed on the
probe table. Iteration speed does not recover after many removals because
the dense keys array is not compacted.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.jena.mem.collection.FastHashBase
FastHashBase.KeyAndIndexConsumer<K> -
Constructor Summary
ConstructorsConstructorDescriptionCreates a set with the default initial capacity.FastHashSet(int initialSize) Creates a set with the given initial key-array capacity. -
Method Summary
Modifier and TypeMethodDescriptionintaddAndGetIndex(K key) Add an element and return the index it was stored at.voidaddUnchecked(K key) Add the key to the set without checking whether it is already present.voidaddUnchecked(K key, int hashCode) Add an element with the given precomputed hash code without checking whether it is already present.voidbooleanAdd the key to the set if it is not already present.booleanAdd an element with the given precomputed hash code if it is not already present.Methods inherited from class org.apache.jena.mem.collection.FastHashBase
anyMatch, anyMatchRandomOrder, clear, containsKey, forEachKey, getKeyAt, indexOf, isEmpty, keyIterator, keySpliterator, removeAndGetIndex, removeUnchecked, removeUnchecked, size, tryRemove, tryRemoveMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.jena.mem.collection.JenaMapSetCommon
anyMatch, clear, containsKey, isEmpty, keyIterator, keySpliterator, keyStream, keyStreamParallel, removeUnchecked, tryRemoveMethods inherited from interface org.apache.jena.mem.collection.JenaSet
iterator, spliteratorMethods inherited from interface org.apache.jena.mem.collection.JenaSetHashOptimized
removeUnchecked, tryRemoveMethods inherited from interface org.apache.jena.mem.collection.JenaSetIndexed
getKeyAt, indexOf, removeAndGetIndex
-
Constructor Details
-
FastHashSet
public FastHashSet(int initialSize) Creates a set with the given initial key-array capacity.- Parameters:
initialSize- the initial capacity of the keys array
-
FastHashSet
public FastHashSet()Creates a set with the default initial capacity.
-
-
Method Details
-
tryAdd
Description copied from interface:JenaSetAdd the key to the set if it is not already present. -
tryAdd
Description copied from interface:JenaSetHashOptimizedAdd an element with the given precomputed hash code if it is not already present.- Specified by:
tryAddin interfaceJenaSetHashOptimized<K>- Parameters:
key- the element to add. (nullis not allowed)hashCode-key.hashCode().- Returns:
trueif added,falseif already present
-
addAndGetIndex
Add an element and return the index it was stored at. If the element is already present, returns the bitwise complement (~existingIndex) of the existing index, so callers can distinguish "newly inserted" from "already present" while still recovering the index in both cases.- Specified by:
addAndGetIndexin interfaceJenaSetIndexed<K>- Parameters:
key- the element to add- Returns:
- the new index, or
~existingIndexif already present
-
addUnchecked
Description copied from interface:JenaSetAdd the key to the set without checking whether it is already present.Attention: this method must only be used if the caller has ensured that the key is not already in the set; otherwise the set's invariants will break (duplicates may be inserted).
- Specified by:
addUncheckedin interfaceJenaSet<K>- Parameters:
key- the key to add. (nullis not allowed)
-
addUnchecked
Description copied from interface:JenaSetHashOptimizedAdd an element with the given precomputed hash code without checking whether it is already present. The caller MUST ensure the key is absent.- Specified by:
addUncheckedin interfaceJenaSetHashOptimized<K>- Parameters:
key- the element to add. (nullis not allowed)hashCode-key.hashCode(). (nullis not allowed)
-
forEach
-