Class PathCopyingPersistentTreeMap<K extends Comparable<? super K>,V extends @Nullable Object>
- Type Parameters:
K- The type of keys.V- The type of values.
- All Implemented Interfaces:
Serializable,Map<K,,V> NavigableMap<K,,V> SortedMap<K,,V> PersistentMap<K,,V> PersistentSortedMap<K,V>
PersistentSortedMap that is based on left-leaning red-black
trees (LLRB) and path copying. Left-leaning red-black trees are similar to red-black trees and
2-3 trees, but are considerably easier to implement than red-black trees. They are described by
Robert Sedgewick here: http://www.cs.princeton.edu/~rs/talks/LLRB/RedBlack.pdf
The operations insert, lookup, and remove are guaranteed to run in O(log n) time. Insert and
remove allocate at most O(log n) memory. Traversal through all entries also allocates up to O(log
n) memory. Per entry, this map needs memory for one object with 4 reference fields and 1 boolean.
(This is a little bit less than TreeMap needs.)
This implementation does not support null keys (but null values) and
always compares according to the natural ordering. All methods may throw ClassCastException is key objects are passed that do not implement Comparable.
The natural ordering of the keys needs to be consistent with equals.
As for all PersistentMaps, all collection views and all iterators are immutable. They
do not reflect changes made to the map and all their modifying operations throw UnsupportedOperationException.
All instances of this class are fully-thread safe. However, note that each modifying operation allocates a new instance whose reference needs to be published safely in order to be usable by other threads. Two concurrent accesses to a modifying operation on the same instance will create two new maps, each reflecting exactly the operation executed by the current thread, and not reflecting the operation executed by the other thread.
- See Also:
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionceilingEntry(K pKey) final KceilingKey(K pKey) final voidclear()Deprecated.@Nullable Comparator<? super K>final VDeprecated.final VcomputeIfAbsent(K pKey, Function<? super K, ? extends V> pMappingFunction) Deprecated.final VcomputeIfPresent(K pKey, BiFunction<? super K, ? super V, ? extends V> pRemappingFunction) Deprecated.booleancontainsKey(Object pObj) booleancontainsValue(Object pValue) static <K extends Comparable<? super K>,V extends @Nullable Object>
PersistentSortedMap<K,V> final NavigableSet<K>empty()Replacement for {PersistentMap.clear()that returns an empty instance.entrySet()booleanfinal KfirstKey()floorEntry(K pKey) final K@Nullable VgetOrDefault(Object pKey, V pDefaultValue) inthashCode()higherEntry(K pKey) final KbooleanisEmpty()final NavigableSet<K>keySet()final KlastKey()lowerEntry(K pKey) final Kfinal VDeprecated.static <K extends Comparable<? super K>,V extends @Nullable Object>
PersistentSortedMap<K,V> of()Deprecated.Deprecated.final VDeprecated.final voidDeprecated.putAndCopy(K key, V value) Replacement for {PersistentMap.put(Object, Object)that returns a fresh instance.final VputIfAbsent(K pKey, V pValue) Deprecated.final VDeprecated.final booleanDeprecated.removeAndCopy(Object key) Replacement for {PersistentMap.remove(Object)that returns a fresh instance.final VDeprecated.final booleanDeprecated.final voidreplaceAll(BiFunction<? super K, ? super V, ? extends V> pFunction) Deprecated.intsize()static <T,K extends Comparable<? super K>, V extends @Nullable Object>
Collector<T,?, PersistentSortedMap<K, V>> toPathCopyingPersistentTreeMap(Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction) Return aCollectorthat accumulates elements into aPathCopyingPersistentTreeMap.static <T,K extends Comparable<? super K>, V extends @Nullable Object>
Collector<T,?, PersistentSortedMap<K, V>> toPathCopyingPersistentTreeMap(Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction, BinaryOperator<V> mergeFunction) Return aCollectorthat accumulates elements into aPathCopyingPersistentTreeMap.toString()values()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
containsValue, forEachMethods inherited from interface java.util.NavigableMap
ceilingKey, descendingKeySet, floorKey, higherKey, lowerKey, navigableKeySetMethods inherited from interface org.sosy_lab.common.collect.PersistentMap
clear, compute, computeIfAbsent, computeIfPresent, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAllMethods inherited from interface org.sosy_lab.common.collect.PersistentSortedMap
headMap, keySet, pollFirstEntry, pollLastEntry, subMap, tailMap
-
Method Details
-
of
public static <K extends Comparable<? super K>,V extends @Nullable Object> PersistentSortedMap<K,V> of() -
copyOf
public static <K extends Comparable<? super K>,V extends @Nullable Object> PersistentSortedMap<K,V> copyOf(Map<K, V> map) -
toPathCopyingPersistentTreeMap
public static <T,K extends Comparable<? super K>, Collector<T,V extends @Nullable Object> ?, toPathCopyingPersistentTreeMapPersistentSortedMap<K, V>> (Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction) Return aCollectorthat accumulates elements into aPathCopyingPersistentTreeMap. Keys and values are the result of the respective functions. If duplicate keys appear, the collector throws anIllegalArgumentException. -
toPathCopyingPersistentTreeMap
public static <T,K extends Comparable<? super K>, Collector<T,V extends @Nullable Object> ?, toPathCopyingPersistentTreeMapPersistentSortedMap<K, V>> (Function<? super T, ? extends K> keyFunction, Function<? super T, ? extends V> valueFunction, BinaryOperator<V> mergeFunction) Return aCollectorthat accumulates elements into aPathCopyingPersistentTreeMap. Keys and values are the result of the respective functions. Duplicate keys are resolved using the given merge function. -
putAndCopy
Description copied from interface:PersistentMapReplacement for {PersistentMap.put(Object, Object)that returns a fresh instance.- Specified by:
putAndCopyin interfacePersistentMap<K extends Comparable<? super K>,V extends @Nullable Object> - Specified by:
putAndCopyin interfacePersistentSortedMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
removeAndCopy
Description copied from interface:PersistentMapReplacement for {PersistentMap.remove(Object)that returns a fresh instance.- Specified by:
removeAndCopyin interfacePersistentMap<K extends Comparable<? super K>,V extends @Nullable Object> - Specified by:
removeAndCopyin interfacePersistentSortedMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
equals
-
hashCode
public int hashCode() -
getEntry
-
entryIterator
-
descendingEntryIterator
-
empty
Description copied from interface:PersistentMapReplacement for {PersistentMap.clear()that returns an empty instance.- Specified by:
emptyin interfacePersistentMap<K extends Comparable<? super K>,V extends @Nullable Object> - Specified by:
emptyin interfacePersistentSortedMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
containsKey
- Specified by:
containsKeyin interfaceMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
get
-
getOrDefault
- Specified by:
getOrDefaultin interfaceMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
isEmpty
public boolean isEmpty() -
size
public int size() -
firstEntry
- Specified by:
firstEntryin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
lastEntry
- Specified by:
lastEntryin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
ceilingEntry
- Specified by:
ceilingEntryin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
floorEntry
- Specified by:
floorEntryin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
higherEntry
- Specified by:
higherEntryin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
lowerEntry
- Specified by:
lowerEntryin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
comparator
- Specified by:
comparatorin interfaceSortedMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
descendingMap
- Specified by:
descendingMapin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object> - Specified by:
descendingMapin interfacePersistentSortedMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
entrySet
- Specified by:
entrySetin interfaceMap<K extends Comparable<? super K>,V extends @Nullable Object> - Specified by:
entrySetin interfacePersistentSortedMap<K extends Comparable<? super K>,V extends @Nullable Object> - Specified by:
entrySetin interfaceSortedMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
subMap
public org.sosy_lab.common.collect.OurSortedMap<K,V> subMap(K pFromKey, boolean pFromInclusive, K pToKey, boolean pToInclusive) - Specified by:
subMapin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object> - Specified by:
subMapin interfacePersistentSortedMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
headMap
- Specified by:
headMapin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object> - Specified by:
headMapin interfacePersistentSortedMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
tailMap
- Specified by:
tailMapin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object> - Specified by:
tailMapin interfacePersistentSortedMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
firstKey
-
lastKey
-
ceilingKey
- Specified by:
ceilingKeyin interfaceNavigableMap<K,V extends @Nullable Object>
-
floorKey
- Specified by:
floorKeyin interfaceNavigableMap<K,V extends @Nullable Object>
-
higherKey
- Specified by:
higherKeyin interfaceNavigableMap<K,V extends @Nullable Object>
-
lowerKey
- Specified by:
lowerKeyin interfaceNavigableMap<K,V extends @Nullable Object>
-
headMap
-
tailMap
-
subMap
-
keySet
-
descendingKeySet
- Specified by:
descendingKeySetin interfaceNavigableMap<K,V extends @Nullable Object>
-
pollFirstEntry
Deprecated.- Specified by:
pollFirstEntryin interfaceNavigableMap<K,V extends @Nullable Object>
-
pollLastEntry
Deprecated.- Specified by:
pollLastEntryin interfaceNavigableMap<K,V extends @Nullable Object>
-
clear
Deprecated. -
put
Deprecated. -
putIfAbsent
Deprecated.- Specified by:
putIfAbsentin interfaceMap<K,V extends @Nullable Object>
-
putAll
Deprecated. -
remove
Deprecated. -
remove
Deprecated. -
replace
Deprecated. -
replace
Deprecated. -
compute
@Deprecated public final V compute(K pKey, BiFunction<? super K, ? super V, ? extends V> pRemappingFunction) Deprecated. -
computeIfAbsent
@Deprecated public final V computeIfAbsent(K pKey, Function<? super K, ? extends V> pMappingFunction) Deprecated.- Specified by:
computeIfAbsentin interfaceMap<K,V extends @Nullable Object>
-
computeIfPresent
@Deprecated public final V computeIfPresent(K pKey, BiFunction<? super K, ? super V, ? extends V> pRemappingFunction) Deprecated.- Specified by:
computeIfPresentin interfaceMap<K,V extends @Nullable Object>
-
merge
@Deprecated public final V merge(K pKey, V pValue, BiFunction<? super V, ? super V, ? extends V> pRemappingFunction) Deprecated. -
replaceAll
Deprecated.- Specified by:
replaceAllin interfaceMap<K,V extends @Nullable Object>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V extends @Nullable Object>
-
values
-
toString
-