- Type Parameters:
K- the type of the keys
- All Implemented Interfaces:
JenaMapSetCommon<K>
- Direct Known Subclasses:
FastHashMap,FastHashSet
FastHashSet and FastHashSet.
It only grows but never shrinks.
This map does not guarantee any order. Although due to the way it is implemented the elements have a certain order.
This map does not allow null keys.
This map is not thread safe.
The positions array stores negative indices to the entries and hashCode arrays.
The positions array is implemented as a power of two sized array. (like in HashMap) This allows
to use a fast modulo operation to calculate the index. The indices of the positions array are derived from the
hashCodes.
Any position 0 indicates an empty element. The comparison with 0 is faster than comparing elements with null.
The keys are stored in a keys array and the hashCodesOrDeletedIndices array
stores the hashCodes of the keys.
hashCodesOrDeletedIndices is also used to store the indices of the deleted keys to save memory. It works like a
linked list of deleted keys. The index of the previously deleted key is stored in the hashCodesOrDeletedIndices
array. lastDeletedIndex is the index of the last deleted key in the hashCodesOrDeletedIndices array and serves as
the head of the linked list of deleted keys.
These two arrays grow together. They grow like ArrayList with a factor of 1.5.
keysPos is the index of the next free position in the keys array. The keys array is usually completely filled from index 0 to keysPos. Exceptions are the deleted keys. Indices that have been deleted are reused for new keys before the keys array is extended. The dense nature of the keys array enables fast iteration.
The index of a key in the keys array never changes. So the index of a key can be used as a handle to the key and for random access.
-
Method Summary
Modifier and TypeMethodDescriptionfinal booleanAttentions: Due to the ordering of the keys, this method may be slow if matching elements are at the start of the list.final booleananyMatchRandomOrder(Predicate<K> predicate) This method can be faster thananyMatch(Predicate)if one expects to find many matches.voidclear()Removes all the elements from this collection (optional operation).final booleancontainsKey(K o) Check whether the collection contains a given key.final booleanisEmpty()Returnstrueif this collection contains no elements.final ExtendedIterator<K>Get an iterator over the keys in the collection.final Spliterator<K>Get a spliterator over the keys in the collection.final intRemoves the element at the given position.final intremoveAndGetIndex(K e, int hashCode) Removes the element at the given position.final voidremoveUnchecked(K e) Removes a key from the collection.final voidremoveUnchecked(K e, int hashCode) intsize()Returns the number of elements in this collection.final booleanTries to remove a key from the collection.final booleanMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.jena.mem2.collection.JenaMapSetCommon
keyStream, keyStreamParallel
-
Method Details
-
size
public int size()Returns the number of elements in this collection. If this collection contains more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.- Specified by:
sizein interfaceJenaMapSetCommon<K>- Returns:
- the number of elements in this collection
-
tryRemove
Description copied from interface:JenaMapSetCommonTries to remove a key from the collection.- Specified by:
tryRemovein interfaceJenaMapSetCommon<K>- Parameters:
o- the key to remove- Returns:
- true if the key was removed. If the key was not present, false is returned.
-
tryRemove
-
removeAndGetIndex
Removes the element at the given position.- Parameters:
e- the element- Returns:
- the index of the removed element or -1 if the element was not found
-
removeAndGetIndex
Removes the element at the given position.- Parameters:
e- the elementhashCode- the hash code of the element. This is a performance optimization.- Returns:
- the index of the removed element or -1 if the element was not found
-
removeUnchecked
Description copied from interface:JenaMapSetCommonRemoves a key from the collection. Attention: Implementations may assume that the key is present.- Specified by:
removeUncheckedin interfaceJenaMapSetCommon<K>- Parameters:
e- the key to remove
-
removeUnchecked
-
isEmpty
public final boolean isEmpty()Returnstrueif this collection contains no elements.- Specified by:
isEmptyin interfaceJenaMapSetCommon<K>- Returns:
trueif this collection contains no elements
-
containsKey
Description copied from interface:JenaMapSetCommonCheck whether the collection contains a given key.- Specified by:
containsKeyin interfaceJenaMapSetCommon<K>- Parameters:
o- the key to look for- Returns:
- true if the collection contains the key
-
anyMatch
Attentions: Due to the ordering of the keys, this method may be slow if matching elements are at the start of the list. Try to useanyMatchRandomOrder(Predicate)instead.- Specified by:
anyMatchin interfaceJenaMapSetCommon<K>- Parameters:
predicate- the predicate to match- Returns:
- true if the collection contains any element matching the predicate
-
anyMatchRandomOrder
This method can be faster thananyMatch(Predicate)if one expects to find many matches. But it is slower if one expects to find no matches or just a single one.- Parameters:
predicate- the predicate to apply to elements of this collection- Returns:
trueif any element of the collection matches the predicate
-
keyIterator
Description copied from interface:JenaMapSetCommonGet an iterator over the keys in the collection.- Specified by:
keyIteratorin interfaceJenaMapSetCommon<K>- Returns:
- an iterator over the keys in the collection
-
clear
public void clear()Removes all the elements from this collection (optional operation). The collection will be empty after this method returns.- Specified by:
clearin interfaceJenaMapSetCommon<K>- Throws:
UnsupportedOperationException- if theclearoperation is not supported by this collection
-
keySpliterator
Description copied from interface:JenaMapSetCommonGet a spliterator over the keys in the collection.- Specified by:
keySpliteratorin interfaceJenaMapSetCommon<K>- Returns:
- a spliterator over the keys in the collection
-