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
Modifier and TypeClassDescriptionprotected static final class
protected static final class
static class
protected static class
protected static final class
protected class
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final Comparator
<UnsignedInteger> protected final int
protected NavigableMap
<UnsignedInteger, E> protected int
protected final RingQueue
<SplayMap.SplayedEntry<E>> protected Set
<Map.Entry<UnsignedInteger, E>> protected NavigableSet
<UnsignedInteger> protected int
protected static final Comparator
<UnsignedInteger> protected SplayMap.SplayedEntry
<E> Root node which can be null if the tree has no elements (size == 0)protected int
Current size of the splayed map tree.protected Collection
<E> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Comparator
<? super UnsignedInteger> 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.boolean
containsKey
(Object key) boolean
containsValue
(Object value) protected void
delete
(SplayMap.SplayedEntry<E> node) protected void
entryAdded
(SplayMap.SplayedEntry<E> newEntry) protected void
entryDeleted
(SplayMap.SplayedEntry<E> deletedEntry) entrySet()
boolean
protected static <V> SplayMap.ImmutableSplayMapEntry
<V> export
(SplayMap.SplayedEntry<V> entry) firstKey()
floorKey
(UnsignedInteger key) void
forEach
(BiConsumer<? super UnsignedInteger, ? super E> action) void
get
(int key) Gets the value of the element stored in theMap
with the key (treated as an unsigned integer for comparison.getOrDefault
(int key, E defaultValue) Gets the value of the element stored in theMap
with the key (treated as an unsigned integer for comparison.getOrDefault
(Object key, E defaultValue) int
hashCode()
headMap
(UnsignedInteger toKey) headMap
(UnsignedInteger toKey, boolean inclusive) higherKey
(UnsignedInteger key) boolean
isEmpty()
keySet()
lastKey()
lowerKey
(UnsignedInteger key) Puts the value into the in theMap
at the entry specified by the given key (treated as an unsigned integer for comparison.put
(UnsignedInteger key, E value) void
putAll
(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 primitiveint
key 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.boolean
Removes the entry for the specified primitive int (treated as unsigned) key only if it is currently mapped to the specified value in theMap
.boolean
remove
(UnsignedInteger key) Removes the mapping for theUnsignedInteger
key 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 theMap
with the new value provided.boolean
Replaces the entry for the specified primitive int (treated as unsigned) key only if it is currently mapped to the specified value in theMap
with the new value provided.replace
(UnsignedInteger key, E value) boolean
replace
(UnsignedInteger key, E oldValue, E newValue) void
replaceAll
(BiFunction<? super UnsignedInteger, ? super E, ? extends E> function) protected static Comparator
<? super UnsignedInteger> int
size()
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, wait
Methods 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:
size
in interfaceMap<UnsignedInteger,
E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceMap<UnsignedInteger,
E>
-
get
Gets the value of the element stored in theMap
with 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 theMap
with 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 theMap
at 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 theUnsignedInteger
key 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
- TheUnsignedInteger
key 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 primitiveint
key 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
- TheUnsignedInteger
key 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:
true
if the key mapping is found within thisMap
.
-
put
- Specified by:
put
in interfaceMap<UnsignedInteger,
E>
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceMap<UnsignedInteger,
E>
-
get
- Specified by:
get
in interfaceMap<UnsignedInteger,
E>
-
getOrDefault
- Specified by:
getOrDefault
in interfaceMap<UnsignedInteger,
E>
-
remove
- Specified by:
remove
in interfaceMap<UnsignedInteger,
E>
-
containsKey
- Specified by:
containsKey
in interfaceMap<UnsignedInteger,
E>
-
clear
public void clear()- Specified by:
clear
in interfaceMap<UnsignedInteger,
E>
-
putAll
- Specified by:
putAll
in interfaceMap<UnsignedInteger,
E>
-
containsValue
- Specified by:
containsValue
in interfaceMap<UnsignedInteger,
E>
-
hashCode
public int hashCode() -
equals
-
keySet
- Specified by:
keySet
in interfaceMap<UnsignedInteger,
E> - Specified by:
keySet
in interfaceSortedMap<UnsignedInteger,
E>
-
values
- Specified by:
values
in interfaceMap<UnsignedInteger,
E> - Specified by:
values
in interfaceSortedMap<UnsignedInteger,
E>
-
entrySet
- Specified by:
entrySet
in interfaceMap<UnsignedInteger,
E> - Specified by:
entrySet
in interfaceSortedMap<UnsignedInteger,
E>
-
forEach
- Specified by:
forEach
in interfaceMap<UnsignedInteger,
E>
-
forEach
A specialized forEach implementation that accepts aConsumer
function 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:
replaceAll
in interfaceMap<UnsignedInteger,
E>
-
remove
- Specified by:
remove
in 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:
true
if an entry was removed from theMap
-
replace
- Specified by:
replace
in 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 theMap
with 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:
true
if an entry was replaced in theMap
-
replace
- Specified by:
replace
in 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 theMap
with 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:
true
if an entry was replaced in theMap
-
entryAdded
-
entryDeleted
-
delete
-
export
-
reverseComparator
-
comparator
- Specified by:
comparator
in interfaceSortedMap<UnsignedInteger,
E>
-
firstKey
- Specified by:
firstKey
in interfaceSortedMap<UnsignedInteger,
E>
-
lastKey
- Specified by:
lastKey
in interfaceSortedMap<UnsignedInteger,
E>
-
firstEntry
- Specified by:
firstEntry
in interfaceNavigableMap<UnsignedInteger,
E>
-
lastEntry
- Specified by:
lastEntry
in interfaceNavigableMap<UnsignedInteger,
E>
-
pollFirstEntry
- Specified by:
pollFirstEntry
in interfaceNavigableMap<UnsignedInteger,
E>
-
pollLastEntry
- Specified by:
pollLastEntry
in interfaceNavigableMap<UnsignedInteger,
E>
-
lowerEntry
- Specified by:
lowerEntry
in interfaceNavigableMap<UnsignedInteger,
E>
-
lowerKey
- Specified by:
lowerKey
in interfaceNavigableMap<UnsignedInteger,
E>
-
higherEntry
- Specified by:
higherEntry
in interfaceNavigableMap<UnsignedInteger,
E>
-
higherKey
- Specified by:
higherKey
in interfaceNavigableMap<UnsignedInteger,
E>
-
floorEntry
- Specified by:
floorEntry
in interfaceNavigableMap<UnsignedInteger,
E>
-
floorKey
- Specified by:
floorKey
in interfaceNavigableMap<UnsignedInteger,
E>
-
ceilingEntry
- Specified by:
ceilingEntry
in interfaceNavigableMap<UnsignedInteger,
E>
-
ceilingKey
- Specified by:
ceilingKey
in interfaceNavigableMap<UnsignedInteger,
E>
-
descendingMap
- Specified by:
descendingMap
in interfaceNavigableMap<UnsignedInteger,
E>
-
descendingKeySet
- Specified by:
descendingKeySet
in interfaceNavigableMap<UnsignedInteger,
E>
-
subMap
public NavigableMap<UnsignedInteger,E> subMap(UnsignedInteger fromKey, boolean fromInclusive, UnsignedInteger toKey, boolean toInclusive) - Specified by:
subMap
in interfaceNavigableMap<UnsignedInteger,
E>
-
headMap
- Specified by:
headMap
in interfaceNavigableMap<UnsignedInteger,
E>
-
tailMap
- Specified by:
tailMap
in interfaceNavigableMap<UnsignedInteger,
E>
-
subMap
- Specified by:
subMap
in interfaceNavigableMap<UnsignedInteger,
E> - Specified by:
subMap
in interfaceSortedMap<UnsignedInteger,
E>
-
headMap
- Specified by:
headMap
in interfaceNavigableMap<UnsignedInteger,
E> - Specified by:
headMap
in interfaceSortedMap<UnsignedInteger,
E>
-
tailMap
- Specified by:
tailMap
in interfaceNavigableMap<UnsignedInteger,
E> - Specified by:
tailMap
in interfaceSortedMap<UnsignedInteger,
E>
-