Class SplayMap<E>
java.lang.Object
org.apache.qpid.protonj2.engine.util.SplayMap<E>
- Type Parameters:
E- The type stored in the map entries
- All Implemented Interfaces:
Map<UnsignedInteger,,E> NavigableMap<UnsignedInteger,,E> SortedMap<UnsignedInteger,E>
- Direct Known Subclasses:
LinkedSplayMap
Map class that is implemented using a Splay Tree and uses primitive integers as the keys
for the specified value type.
The splay tree is a specialized form of a binary search tree that is self balancing and
provides faster access in general to frequently used items. The splay tree serves well
as an LRU cache of sorts where 80 percent of the accessed elements comes from 20 percent
of the overall load in the
Map. The best case access time is generally O(long n)
however it can be Theta(n) in a very worst case scenario.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final classprotected static final classstatic classprotected static classprotected static final classprotected class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Comparator<UnsignedInteger>protected final intprotected NavigableMap<UnsignedInteger,E> protected intprotected final RingQueue<SplayMap.SplayedEntry<E>>protected Set<Map.Entry<UnsignedInteger,E>> protected NavigableSet<UnsignedInteger>protected intprotected static final Comparator<UnsignedInteger>protected SplayMap.SplayedEntry<E>Root node which can be null if the tree has no elements (size == 0)protected intCurrent size of the splayed map tree.protected Collection<E> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Comparator<? super UnsignedInteger>booleancontainsKey(int key) Searches the map using the given primitive integer key value which will be treated internally as an unsigned value when comparing against keys in the mapping.booleancontainsKey(Object key) booleancontainsValue(Object value) protected voiddelete(SplayMap.SplayedEntry<E> node) protected voidentryAdded(SplayMap.SplayedEntry<E> newEntry) protected voidentryDeleted(SplayMap.SplayedEntry<E> deletedEntry) entrySet()booleanprotected static <V> SplayMap.ImmutableSplayMapEntry<V>export(SplayMap.SplayedEntry<V> entry) firstKey()floorKey(UnsignedInteger key) voidforEach(BiConsumer<? super UnsignedInteger, ? super E> action) voidget(int key) Gets the value of the element stored in theMapwith the key (treated as an unsigned integer for comparison.getOrDefault(int key, E defaultValue) Gets the value of the element stored in theMapwith the key (treated as an unsigned integer for comparison.getOrDefault(Object key, E defaultValue) inthashCode()headMap(UnsignedInteger toKey) headMap(UnsignedInteger toKey, boolean inclusive) higherKey(UnsignedInteger key) booleanisEmpty()keySet()lastKey()lowerKey(UnsignedInteger key) Puts the value into the in theMapat the entry specified by the given key (treated as an unsigned integer for comparison.put(UnsignedInteger key, E value) voidputAll(Map<? extends UnsignedInteger, ? extends E> source) putIfAbsent(int key, E value) If the specified key is not already associated with a value associates it with the given value and returns null, otherwise returns the current value.putIfAbsent(UnsignedInteger key, E value) remove(int key) Removes the mapping for the primitiveintkey from this map if it is present and returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.booleanRemoves the entry for the specified primitive int (treated as unsigned) key only if it is currently mapped to the specified value in theMap.booleanremove(UnsignedInteger key) Removes the mapping for theUnsignedIntegerkey from this map if it is present and returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.Replaces the entry for the specified primitive int (treated as unsigned) key only if it is currently mapped to the a value in theMapwith the new value provided.booleanReplaces the entry for the specified primitive int (treated as unsigned) key only if it is currently mapped to the specified value in theMapwith the new value provided.replace(UnsignedInteger key, E value) booleanreplace(UnsignedInteger key, E oldValue, E newValue) voidreplaceAll(BiFunction<? super UnsignedInteger, ? super E, ? extends E> function) protected static Comparator<? super UnsignedInteger>intsize()subMap(UnsignedInteger fromKey, boolean fromInclusive, UnsignedInteger toKey, boolean toInclusive) subMap(UnsignedInteger fromKey, UnsignedInteger toKey) tailMap(UnsignedInteger fromKey) tailMap(UnsignedInteger fromKey, boolean inclusive) values()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, merge
-
Field Details
-
COMPARATOR
-
REVERSE_COMPARATOR
-
DEFAULT_ENTRY_POOL_SIZE
protected final int DEFAULT_ENTRY_POOL_SIZE- See Also:
-
entryPool
-
entriesInExistence
protected int entriesInExistence -
root
Root node which can be null if the tree has no elements (size == 0) -
size
protected int sizeCurrent size of the splayed map tree. -
modCount
protected int modCount -
keySet
-
values
-
entrySet
-
descendingMapView
-
-
Constructor Details
-
SplayMap
public SplayMap()
-
-
Method Details
-
size
public int size()- Specified by:
sizein interfaceMap<UnsignedInteger,E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceMap<UnsignedInteger,E>
-
get
Gets the value of the element stored in theMapwith the key (treated as an unsigned integer for comparison. As a side effect of calling this method the tree that comprises the Map can be modified to bring up the found key or the last accessed key if the key given is not in theMap. For entries at the root of the tree that match the given search key the method returns immediately without modifying theMap. -
getOrDefault
Gets the value of the element stored in theMapwith the key (treated as an unsigned integer for comparison. As a side effect of calling this method the tree that comprises the Map can be modified to bring up the found key or the last accessed key if the key given is not in theMap. For entries at the root of the tree that match the given search key the method returns immediately without modifying theMap. -
put
Puts the value into the in theMapat the entry specified by the given key (treated as an unsigned integer for comparison. As a side effect of calling this method the tree that comprises the Map can be modified to bring up the found key or the last accessed key if the key given is not in theMap. For entries at the root of the tree that match the given search key the method returns immediately without modifying theMap. -
putIfAbsent
If the specified key is not already associated with a value associates it with the given value and returns null, otherwise returns the current value. As a side effect of calling this method the tree that comprises the Map can be modified to bring up the found key or the last accessed key if the key given is not in theMap. For entries at the root of the tree that match the given search key the method returns immediately without modifying theMap.- Parameters:
key- the integer key value to search for and or insert in theSplayMap.value- the value to assign to the entry accessed via the given key.- Returns:
- the previous value associated with the given key or null if none was present.
-
remove
Removes the mapping for theUnsignedIntegerkey from this map if it is present and returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.- Parameters:
key- TheUnsignedIntegerkey whose value will be removed from theSplayMap.- Returns:
- the value that was removed if one was present in the
Map.
-
remove
Removes the mapping for the primitiveintkey from this map if it is present and returns the value to which this map previously associated the key, or null if the map contained no mapping for the key. The integer value is treated as an unsigned int internally.- Parameters:
key- TheUnsignedIntegerkey whose value will be removed from theSplayMap.- Returns:
- the value that was removed if one was present in the
Map.
-
containsKey
public boolean containsKey(int key) Searches the map using the given primitive integer key value which will be treated internally as an unsigned value when comparing against keys in the mapping.- Parameters:
key- The key which will be searched for in this mapping.- Returns:
trueif the key mapping is found within thisMap.
-
put
- Specified by:
putin interfaceMap<UnsignedInteger,E>
-
putIfAbsent
- Specified by:
putIfAbsentin interfaceMap<UnsignedInteger,E>
-
get
- Specified by:
getin interfaceMap<UnsignedInteger,E>
-
getOrDefault
- Specified by:
getOrDefaultin interfaceMap<UnsignedInteger,E>
-
remove
- Specified by:
removein interfaceMap<UnsignedInteger,E>
-
containsKey
- Specified by:
containsKeyin interfaceMap<UnsignedInteger,E>
-
clear
public void clear()- Specified by:
clearin interfaceMap<UnsignedInteger,E>
-
putAll
- Specified by:
putAllin interfaceMap<UnsignedInteger,E>
-
containsValue
- Specified by:
containsValuein interfaceMap<UnsignedInteger,E>
-
hashCode
public int hashCode() -
equals
-
keySet
- Specified by:
keySetin interfaceMap<UnsignedInteger,E> - Specified by:
keySetin interfaceSortedMap<UnsignedInteger,E>
-
values
- Specified by:
valuesin interfaceMap<UnsignedInteger,E> - Specified by:
valuesin interfaceSortedMap<UnsignedInteger,E>
-
entrySet
- Specified by:
entrySetin interfaceMap<UnsignedInteger,E> - Specified by:
entrySetin interfaceSortedMap<UnsignedInteger,E>
-
forEach
- Specified by:
forEachin interfaceMap<UnsignedInteger,E>
-
forEach
A specialized forEach implementation that accepts aConsumerfunction that will be called for each value in theSplayMap. This method can save overhead as it does not need to box the primitive key values into an object for the call to the provided function. Unless otherwise specified by the implementing class, actions are performed in the order of entry set iteration (if an iteration order is specified.)- Parameters:
action- The action to be performed for each of the values in theSplayMap.
-
replaceAll
- Specified by:
replaceAllin interfaceMap<UnsignedInteger,E>
-
remove
- Specified by:
removein interfaceMap<UnsignedInteger,E>
-
remove
Removes the entry for the specified primitive int (treated as unsigned) key only if it is currently mapped to the specified value in theMap.- Parameters:
key- The key whose value will be removed if matched.value- The value that must be contained in the mapping for the remove to be performed.- Returns:
trueif an entry was removed from theMap
-
replace
- Specified by:
replacein interfaceMap<UnsignedInteger,E>
-
replace
Replaces the entry for the specified primitive int (treated as unsigned) key only if it is currently mapped to the specified value in theMapwith the new value provided.- Parameters:
key- The key whose value will be removed if matched.oldValue- The old value that must be contained in the mapping for the replace to be performed.newValue- The value that will replace the old value mapped to the given key if one existed..- Returns:
trueif an entry was replaced in theMap
-
replace
- Specified by:
replacein interfaceMap<UnsignedInteger,E>
-
replace
Replaces the entry for the specified primitive int (treated as unsigned) key only if it is currently mapped to the a value in theMapwith the new value provided.- Parameters:
key- The key whose value will be removed if matched.value- The value that will replace the old value mapped to the given key if one existed..- Returns:
trueif an entry was replaced in theMap
-
entryAdded
-
entryDeleted
-
delete
-
export
-
reverseComparator
-
comparator
- Specified by:
comparatorin interfaceSortedMap<UnsignedInteger,E>
-
firstKey
- Specified by:
firstKeyin interfaceSortedMap<UnsignedInteger,E>
-
lastKey
- Specified by:
lastKeyin interfaceSortedMap<UnsignedInteger,E>
-
firstEntry
- Specified by:
firstEntryin interfaceNavigableMap<UnsignedInteger,E>
-
lastEntry
- Specified by:
lastEntryin interfaceNavigableMap<UnsignedInteger,E>
-
pollFirstEntry
- Specified by:
pollFirstEntryin interfaceNavigableMap<UnsignedInteger,E>
-
pollLastEntry
- Specified by:
pollLastEntryin interfaceNavigableMap<UnsignedInteger,E>
-
lowerEntry
- Specified by:
lowerEntryin interfaceNavigableMap<UnsignedInteger,E>
-
lowerKey
- Specified by:
lowerKeyin interfaceNavigableMap<UnsignedInteger,E>
-
higherEntry
- Specified by:
higherEntryin interfaceNavigableMap<UnsignedInteger,E>
-
higherKey
- Specified by:
higherKeyin interfaceNavigableMap<UnsignedInteger,E>
-
floorEntry
- Specified by:
floorEntryin interfaceNavigableMap<UnsignedInteger,E>
-
floorKey
- Specified by:
floorKeyin interfaceNavigableMap<UnsignedInteger,E>
-
ceilingEntry
- Specified by:
ceilingEntryin interfaceNavigableMap<UnsignedInteger,E>
-
ceilingKey
- Specified by:
ceilingKeyin interfaceNavigableMap<UnsignedInteger,E>
-
descendingMap
- Specified by:
descendingMapin interfaceNavigableMap<UnsignedInteger,E>
-
descendingKeySet
- Specified by:
descendingKeySetin interfaceNavigableMap<UnsignedInteger,E>
-
subMap
public NavigableMap<UnsignedInteger,E> subMap(UnsignedInteger fromKey, boolean fromInclusive, UnsignedInteger toKey, boolean toInclusive) - Specified by:
subMapin interfaceNavigableMap<UnsignedInteger,E>
-
headMap
- Specified by:
headMapin interfaceNavigableMap<UnsignedInteger,E>
-
tailMap
- Specified by:
tailMapin interfaceNavigableMap<UnsignedInteger,E>
-
subMap
- Specified by:
subMapin interfaceNavigableMap<UnsignedInteger,E> - Specified by:
subMapin interfaceSortedMap<UnsignedInteger,E>
-
headMap
- Specified by:
headMapin interfaceNavigableMap<UnsignedInteger,E> - Specified by:
headMapin interfaceSortedMap<UnsignedInteger,E>
-
tailMap
- Specified by:
tailMapin interfaceNavigableMap<UnsignedInteger,E> - Specified by:
tailMapin interfaceSortedMap<UnsignedInteger,E>
-