Top Description Fields Constructors Methods
org.pcollections

public final Class TreePMap<K, V>

extends AbstractUnmodifiableMap<K, V>
implements PSortedMap<K, V>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.pcollections.PSortedMap, java.util.NavigableMap, java.util.SortedMap, java.util.SequencedMap, java.util.Map, org.pcollections.PMap
Type Parameters
<K>
the type of keys maintained by this map
<V>
the type of mapped values
Static Imports
java.util.Objects.requireNonNull

An implementation of PSortedMap based on a self-balancing binary search tree.

Instances of this class are obtained via any of various static factory methods and static collector methods. These methods come in pairs, with one version that accepts an explicit comparator to use and one version that uses the natural ordering of the elements.

All operations are guaranteed to complete within O(log n) time, except for plusAll and minusAll, whose time cost is equivalent to the corresponding sequence of calls to plus or minus. A complete iteration pass over entrySet() completes in O(n) time. A few operations -- namely comparator, descendingKeySet, descendingMap, entrySet, isEmpty, keySet, navigableKeySet, and size -- complete in O(1) time.

Author
Ran Ari-Gur
Since
3.2.0

Field Summary

Modifier and TypeField and Description
private final boolean
private final Comparator<? super K>
private static final long
private final KVTree<K, V>

Constructor Summary

AccessConstructor and Description
private
TreePMap(final KVTree<K, V> tree, final Comparator<? super K> ltrComparator, final boolean isLeftToRight)

Method Summary

Modifier and TypeMethod and Description
public Map.Entry<K, V>
ceilingEntry(final K
the key
key
)

Implements java.util.NavigableMap.ceilingEntry.

Returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such key.

public K
ceilingKey(final K
the key
key
)

Implements java.util.NavigableMap.ceilingKey.

Returns the least key greater than or equal to the given key, or null if there is no such key.

public Comparator<? super K>
comparator()

Implements org.pcollections.PSortedMap.comparator.

Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.

public boolean
containsKey(final Object
key whose presence in this map is to be tested
key
)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public PSortedSet<K>
descendingKeySet()

Implements org.pcollections.PSortedMap.descendingKeySet.

Returns a reverse order NavigableSet view of the keys contained in this map.

public TreePMap<K, V>
descendingMap()

Implements org.pcollections.PSortedMap.descendingMap.

Returns a reverse order view of the mappings contained in this map.

public static <
the type of keys to be maintained by the map
K extends Comparable<? super K>
,
the type of mapped values
V
>
TreePMap<K, V>

Returns:

an empty TreePMap using the natural ordering
empty
()

Returns an empty TreePMap using the natural ordering.

public static <
the type of keys to be maintained by the map
K
,
the type of mapped values
V
>
TreePMap<K, V>

Returns:

an empty TreePMap using the specified comparator
empty
(final Comparator<? super K>
the comparator according to which keys should be ordered
comparator
)

Returns an empty TreePMap using the specified comparator.

public Set<Map.Entry<K, V>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet, java.util.SortedMap.entrySet.

Returns a Set view of the mappings contained in this map.

public Map.Entry<K, V>
firstEntry()

Implements java.util.NavigableMap.firstEntry.

Returns a key-value mapping associated with the least key in this map, or null if the map is empty.

public K
firstKey()

Implements java.util.SortedMap.firstKey.

Returns the first (lowest) key currently in this map.

public Map.Entry<K, V>
floorEntry(final K
the key
key
)

Implements java.util.NavigableMap.floorEntry.

Returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key.

public K
floorKey(final K
the key
key
)

Implements java.util.NavigableMap.floorKey.

Returns the greatest key less than or equal to the given key, or null if there is no such key.

public static <
the type of keys to be maintained by the map
K extends Comparable<? super K>
,
the type of mapped values
V
>
TreePMap<K, V>

Returns:

a TreePMap containing the specified mappings and using the natural ordering of the keys
from
(final Map<? extends K, ? extends V>
the mappings to include
map
)

Returns a TreePMap with the specified mappings, using the natural ordering of the keys.

public static <
the type of keys to be maintained by the map
K
,
the type of mapped values
V
>
TreePMap<K, V>

Returns:

a TreePMap with the specified comparator and mappings
from
(final Comparator<? super K>
the comparator to use
comparator
,
final Map<? extends K, ? extends V>
the mappings to include
map
)

Returns a TreePMap with the specified comparator and mappings.

public static <
the type of keys to be maintained by the map
K
,
the type of mapped values
V
>
TreePMap<K, V>

Returns:

a TreePMap with the same mappings and ordering as the specified set
fromSortedMap
(final SortedMap<K, ? extends V>
the map whose mappings and ordering to use
map
)

Returns a TreePMap with the same mappings and ordering as the specified map.

public V
get(final Object
the key whose associated value is to be returned
key
)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

public TreePMap<K, V>
headMap(final K
high endpoint (exclusive) of the keys in the returned map
toKey
)

Implements org.pcollections.PSortedMap.headMap.

Returns a view of the portion of this map whose keys are strictly less than toKey.

public TreePMap<K, V>
headMap(final K
high endpoint of the keys in the returned map
toKey
,
final boolean
true if the high endpoint is to be included in the returned view
inclusive
)

Implements org.pcollections.PSortedMap.headMap.

Returns a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey.

public Map.Entry<K, V>
higherEntry(final K
the key
key
)

Implements java.util.NavigableMap.higherEntry.

Returns a key-value mapping associated with the least key strictly greater than the given key, or null if there is no such key.

public K
higherKey(final K
the key
key
)

Implements java.util.NavigableMap.higherKey.

Returns the least key strictly greater than the given key, or null if there is no such key.

public boolean
isEmpty()

Overrides java.util.AbstractMap.isEmpty.

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

public TreePSet<K>
keySet()

Overrides java.util.AbstractMap.keySet.

Implements org.pcollections.PSortedMap.keySet, java.util.Map.keySet.

Returns a Set view of the keys contained in this map.

public Map.Entry<K, V>
lastEntry()

Implements java.util.NavigableMap.lastEntry.

Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty.

public K
lastKey()

Implements java.util.SortedMap.lastKey.

Returns the last (highest) key currently in this map.

public Map.Entry<K, V>
lowerEntry(final K
the key
key
)

Implements java.util.NavigableMap.lowerEntry.

Returns a key-value mapping associated with the greatest key strictly less than the given key, or null if there is no such key.

public K
lowerKey(final K
the key
key
)

Implements java.util.NavigableMap.lowerKey.

Returns the greatest key strictly less than the given key, or null if there is no such key.

public TreePMap<K, V>
public TreePMap<K, V>
public TreePMap<K, V>
public TreePMap<K, V>
public TreePMap<K, V>
plus(final K key, final V value)

Implements org.pcollections.PSortedMap.plus.

public TreePMap<K, V>
plusAll(final Map<? extends K, ? extends V> map)

Implements org.pcollections.PSortedMap.plusAll.

private KVTree<K, V>
search(final K key, final KVTree.SearchType searchTypeIfLeftToRight, final KVTree.SearchType searchTypeIfRightToLeft)

public static <
the type of keys to be maintained by the map
K extends Comparable<? super K>
,
the type of mapped values
V
>
TreePMap<K, V>

Returns:

a TreePMap containing the specified mapping and using the natural ordering
singleton
(final K
the key
key
,
final V
the value
value
)

Returns a TreePMap with a single mapping, using the natural ordering of its keys.

public static <
the type of keys to be maintained by the map
K
,
the type of mapped values
V
>
TreePMap<K, V>

Returns:

a TreePMap containing the specified mapping and using the specified comparator
singleton
(final Comparator<? super K>
the comparator according to which keys should be ordered
comparator
,
final K
the key
key
,
final V
the value
value
)

Returns a TreePMap with a single element, using the specified comparator.

public int
size()

Overrides java.util.AbstractMap.size.

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.

private static <T> T
public TreePMap<K, V>
subMap(final K
low endpoint (inclusive) of the keys in the returned map
fromKey
,
final K
high endpoint (exclusive) of the keys in the returned map
toKey
)

Implements org.pcollections.PSortedMap.subMap.

Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive.

public TreePMap<K, V>
subMap(final K
low endpoint of the keys in the returned map
fromKey
,
final boolean
true if the low endpoint is to be included in the returned view
fromInclusive
,
final K
high endpoint of the keys in the returned map
toKey
,
final boolean
true if the high endpoint is to be included in the returned view
toInclusive
)

Implements org.pcollections.PSortedMap.subMap.

Returns a view of the portion of this map whose keys range from fromKey to toKey.

public TreePMap<K, V>
tailMap(final K
low endpoint (inclusive) of the keys in the returned map
fromKey
)

Implements org.pcollections.PSortedMap.tailMap.

Returns a view of the portion of this map whose keys are greater than or equal to fromKey.

public TreePMap<K, V>
tailMap(final K
low endpoint of the keys in the returned map
fromKey
,
final boolean
true if the low endpoint is to be included in the returned view
inclusive
)

Implements org.pcollections.PSortedMap.tailMap.

Returns a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey.

public static <T,
the type of keys to be maintained by the map
K extends Comparable<? super K>
,
the type of mapped values
V
>
Collector<T, ?, TreePMap<K, V>>

Returns:

a collector that gathers the elements of the stream into a TreePMap
toTreePMap
(final Function<? super T, ? extends K>
a function to compute the key from a stream element
keyMapper
,
final Function<? super T, ? extends V>
a function to compute the value from a stream element
valueMapper
)

Returns a collector that gathers a stream into a TreePMap with mappings computed from the elements of the stream (using the specified keyMapper and valueMapper), in the order determined by the natural ordering of the keys.

public static <T,
the type of keys to be maintained by the map
K
,
the type of mapped values
V
>
Collector<T, ?, TreePMap<K, V>>

Returns:

a collector that gathers the elements of the stream into a TreePMap
toTreePMap
(final Comparator<? super K>
the comparator according to which keys should be ordered
comparator
,
final Function<? super T, ? extends K>
a function to compute the key from a stream element
keyMapper
,
final Function<? super T, ? extends V>
a function to compute the value from a stream element
valueMapper
)

Returns a collector that gathers a stream into a TreePMap with mappings computed from the elements of the stream (using the specified keyMapper and valueMapper), in the order determined by the specified comparator.

public static <T,
the type of keys to be maintained by the map
K extends Comparable<? super K>
,
the type of mapped values
V
>
Collector<T, ?, TreePMap<K, V>>

Returns:

a collector that gathers the elements of the stream into a TreePMap
toTreePMap
(final Function<? super T, ? extends K>
a function to compute the key from a stream element
keyMapper
,
final Function<? super T, ? extends V>
a function to compute the value from a stream element
valueMapper
,
final BinaryOperator<V>
a function to merge duplicate values
mergeFunction
)

Returns a collector that gathers a stream into a TreePMap with mappings computed from the elements of the stream (using the specified keyMapper and valueMapper, with duplicates reconciled via the specified mergeFunction), in the order determined by the natural ordering of the keys.

public static <T,
the type of keys to be maintained by the map
K
,
the type of mapped values
V
>
Collector<T, ?, TreePMap<K, V>>

Returns:

a collector that gathers the elements of the stream into a TreePMap
toTreePMap
(final Comparator<? super K>
the comparator according to which keys should be ordered
comparator
,
final Function<? super T, ? extends K>
a function to compute the key from a stream element
keyMapper
,
final Function<? super T, ? extends V>
a function to compute the value from a stream element
valueMapper
,
final BinaryOperator<V>
a function to merge duplicate values
mergeFunction
)

Returns a collector that gathers a stream into a TreePMap with mappings computed from the elements of the stream (using the specified keyMapper and valueMapper, with duplicates reconciled via the specified mergeFunction), in the order determined by the specified comparator.

private TreePMap<K, V>
withTree(final KVTree<K, V> updatedTree)

Inherited from org.pcollections.AbstractUnmodifiableMap:
clearcomputecomputeIfAbsentcomputeIfPresentmergeputputAllputIfAbsentremovereplacereplaceAll