Class PathCopyingPersistentTreeMap<K extends Comparable<? super K>,V extends @Nullable Object>
- java.lang.Object
-
- org.sosy_lab.common.collect.PathCopyingPersistentTreeMap<K,V>
-
- 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>
@Immutable(containerOf={"K","V"}) public final class PathCopyingPersistentTreeMap<K extends Comparable<? super K>,V extends @Nullable Object> extends Object implements PersistentSortedMap<K,V>, SerializableThis is an implementation ofPersistentSortedMapthat 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.pdfThe 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
TreeMapneeds.)This implementation does not support
nullkeys (butnullvalues) and always compares according to the natural ordering. All methods may throwClassCastExceptionis key objects are passed that do not implementComparable.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 throwUnsupportedOperationException.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:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description @Nullable Map.Entry<K,V>ceilingEntry(K pKey)@Nullable KceilingKey(K pKey)voidclear()Deprecated.@Nullable Comparator<? super K>comparator()Vcompute(K pKey, BiFunction<? super K,? super V,? extends V> pRemappingFunction)Deprecated.VcomputeIfAbsent(K pKey, Function<? super K,? extends V> pMappingFunction)Deprecated.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>copyOf(Map<K,V> map)Iterator<Map.Entry<K,V>>descendingEntryIterator()NavigableSet<K>descendingKeySet()org.sosy_lab.common.collect.OurSortedMap<K,V>descendingMap()PersistentSortedMap<K,V>empty()Replacement for {PersistentMap.clear()that returns an empty instance.Iterator<Map.Entry<K,V>>entryIterator()NavigableSet<Map.Entry<K,V>>entrySet()booleanequals(@Nullable Object pObj)@Nullable Map.Entry<K,V>firstEntry()KfirstKey()@Nullable Map.Entry<K,V>floorEntry(K pKey)@Nullable KfloorKey(K pKey)@Nullable Vget(Object pObj)@Nullable Map.Entry<K,V>getEntry(Object pKey)VgetOrDefault(Object pKey, V pDefaultValue)inthashCode()org.sosy_lab.common.collect.OurSortedMap<K,V>headMap(K pToKey)org.sosy_lab.common.collect.OurSortedMap<K,V>headMap(K pToKey, boolean pToInclusive)@Nullable Map.Entry<K,V>higherEntry(K pKey)@Nullable KhigherKey(K pKey)booleanisEmpty()NavigableSet<K>keySet()@Nullable Map.Entry<K,V>lastEntry()KlastKey()@Nullable Map.Entry<K,V>lowerEntry(K pKey)@Nullable KlowerKey(K pKey)Vmerge(K pKey, V pValue, BiFunction<? super V,? super V,? extends V> pRemappingFunction)Deprecated.NavigableSet<K>navigableKeySet()static <K extends Comparable<? super K>,V extends @Nullable Object>
PersistentSortedMap<K,V>of()Map.Entry<K,V>pollFirstEntry()Deprecated.Map.Entry<K,V>pollLastEntry()Deprecated.Vput(K key, V value)Deprecated.voidputAll(Map<? extends K,? extends V> pM)Deprecated.PersistentSortedMap<K,V>putAndCopy(K key, V value)Replacement for {PersistentMap.put(Object, Object)that returns a fresh instance.VputIfAbsent(K pKey, V pValue)Deprecated.Vremove(Object pKey)Deprecated.booleanremove(Object pKey, Object pValue)Deprecated.PersistentSortedMap<K,V>removeAndCopy(Object key)Replacement for {PersistentMap.remove(Object)that returns a fresh instance.Vreplace(K pKey, V pValue)Deprecated.booleanreplace(K pKey, V pOldValue, V pNewValue)Deprecated.voidreplaceAll(BiFunction<? super K,? super V,? extends V> pFunction)Deprecated.intsize()org.sosy_lab.common.collect.OurSortedMap<K,V>subMap(K pFromKey, boolean pFromInclusive, K pToKey, boolean pToInclusive)org.sosy_lab.common.collect.OurSortedMap<K,V>subMap(K pFromKey, K pToKey)org.sosy_lab.common.collect.OurSortedMap<K,V>tailMap(K pFromKey)org.sosy_lab.common.collect.OurSortedMap<K,V>tailMap(K pFromKey, boolean pFromInclusive)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.StringtoString()Collection<V>values()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
containsValue, forEach
-
Methods inherited from interface java.util.NavigableMap
ceilingKey, descendingKeySet, floorKey, higherKey, lowerKey, navigableKeySet
-
Methods inherited from interface org.sosy_lab.common.collect.PersistentMap
clear, compute, computeIfAbsent, computeIfPresent, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll
-
Methods inherited from interface org.sosy_lab.common.collect.PersistentSortedMap
headMap, keySet, pollFirstEntry, pollLastEntry, subMap, tailMap
-
-
-
-
Method Detail
-
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>,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. 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>,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. Keys and values are the result of the respective functions. Duplicate keys are resolved using the given merge function.
-
putAndCopy
public PersistentSortedMap<K,V> putAndCopy(K key, V value)
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
public PersistentSortedMap<K,V> removeAndCopy(Object key)
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
public boolean equals(@Nullable Object pObj)
-
hashCode
public int hashCode()
-
empty
public PersistentSortedMap<K,V> 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
public boolean containsKey(Object pObj)
- Specified by:
containsKeyin interfaceMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
getOrDefault
public V getOrDefault(Object pKey, V pDefaultValue)
- Specified by:
getOrDefaultin interfaceMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
isEmpty
public boolean isEmpty()
-
size
public int size()
-
firstEntry
public @Nullable Map.Entry<K,V> firstEntry()
- Specified by:
firstEntryin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
lastEntry
public @Nullable Map.Entry<K,V> lastEntry()
- Specified by:
lastEntryin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
ceilingEntry
public @Nullable Map.Entry<K,V> ceilingEntry(K pKey)
- Specified by:
ceilingEntryin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
floorEntry
public @Nullable Map.Entry<K,V> floorEntry(K pKey)
- Specified by:
floorEntryin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
higherEntry
public @Nullable Map.Entry<K,V> higherEntry(K pKey)
- Specified by:
higherEntryin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
lowerEntry
public @Nullable Map.Entry<K,V> lowerEntry(K pKey)
- Specified by:
lowerEntryin interfaceNavigableMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
comparator
public @Nullable Comparator<? super K> comparator()
- Specified by:
comparatorin interfaceSortedMap<K extends Comparable<? super K>,V extends @Nullable Object>
-
descendingMap
public org.sosy_lab.common.collect.OurSortedMap<K,V> 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
public NavigableSet<Map.Entry<K,V>> 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
public org.sosy_lab.common.collect.OurSortedMap<K,V> headMap(K pToKey, boolean pToInclusive)
- 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
public org.sosy_lab.common.collect.OurSortedMap<K,V> tailMap(K pFromKey, boolean pFromInclusive)
- 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
public final K firstKey()
-
lastKey
public final K lastKey()
-
ceilingKey
public final @Nullable K ceilingKey(K pKey)
- Specified by:
ceilingKeyin interfaceNavigableMap<K,V extends @Nullable Object>
-
floorKey
public final @Nullable K floorKey(K pKey)
- Specified by:
floorKeyin interfaceNavigableMap<K,V extends @Nullable Object>
-
higherKey
public final @Nullable K higherKey(K pKey)
- Specified by:
higherKeyin interfaceNavigableMap<K,V extends @Nullable Object>
-
lowerKey
public final @Nullable K lowerKey(K pKey)
- Specified by:
lowerKeyin interfaceNavigableMap<K,V extends @Nullable Object>
-
headMap
public final org.sosy_lab.common.collect.OurSortedMap<K,V> headMap(K pToKey)
-
tailMap
public final org.sosy_lab.common.collect.OurSortedMap<K,V> tailMap(K pFromKey)
-
subMap
public final org.sosy_lab.common.collect.OurSortedMap<K,V> subMap(K pFromKey, K pToKey)
-
keySet
public final NavigableSet<K> keySet()
-
navigableKeySet
public NavigableSet<K> navigableKeySet()
- Specified by:
navigableKeySetin interfaceNavigableMap<K,V extends @Nullable Object>
-
descendingKeySet
public final NavigableSet<K> descendingKeySet()
- Specified by:
descendingKeySetin interfaceNavigableMap<K,V extends @Nullable Object>
-
pollFirstEntry
@Deprecated public final Map.Entry<K,V> pollFirstEntry()
Deprecated.- Specified by:
pollFirstEntryin interfaceNavigableMap<K,V extends @Nullable Object>
-
pollLastEntry
@Deprecated public final Map.Entry<K,V> pollLastEntry()
Deprecated.- Specified by:
pollLastEntryin interfaceNavigableMap<K,V extends @Nullable Object>
-
clear
@Deprecated public final void clear()
Deprecated.
-
put
@Deprecated public final V put(K key, V value)
Deprecated.
-
putIfAbsent
@Deprecated public final V putIfAbsent(K pKey, V pValue)
Deprecated.- Specified by:
putIfAbsentin interfaceMap<K,V extends @Nullable Object>
-
putAll
@Deprecated public final void putAll(Map<? extends K,? extends V> pM)
Deprecated.
-
remove
@Deprecated public final V remove(Object pKey)
Deprecated.
-
remove
@Deprecated public final boolean remove(Object pKey, Object pValue)
Deprecated.
-
replace
@Deprecated public final V replace(K pKey, V pValue)
Deprecated.
-
replace
@Deprecated public final boolean replace(K pKey, V pOldValue, V pNewValue)
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 public final void replaceAll(BiFunction<? super K,? super V,? extends V> pFunction)
Deprecated.- Specified by:
replaceAllin interfaceMap<K,V extends @Nullable Object>
-
containsValue
public boolean containsValue(Object pValue)
- Specified by:
containsValuein interfaceMap<K,V extends @Nullable Object>
-
values
public Collection<V> values()
-
-