shadow:utility@OrderedMap<K,V>
class TreeMap<K is CanCompare<K>, V is CanEqual<V>>
Class TreeMap<K,V>
stores an ordered map, also known as an ordered symbol table, of key-value pairs with entries mapping keys of type K
to values of type V
. This ordered map is implemented with a left-leaning red-black binary search tree based on a Shadow port of Sedgewick and Wayne's Java implementation of a left-leaning red-black binary search tree, allowing keys to be added, found, and deleted in logarithmic time. TreeMap<K,V>
requires that type K
has the CanCompare<K>
interface, imposing an ordering on the keys. If ordering of keys is not required, the HashMap<K,V>
class may provide a faster implementation of a map.
Modifiers | Return Types | Method and Description |
---|---|---|
public |
() |
create() |
Modifiers | Return Types | Method and Description |
---|---|---|
public |
() |
destroy() |
Modifiers | Return Types | Method and Description |
---|---|---|
public |
(nullable V) |
add(K key, V value) Stores value object in the location associated with the key and returns the old value if there was one at that location. |
public readonly |
(nullable K) |
ceiling(K key) Returns the smallest key in the ordered map greater than or equal to the given key. |
public |
(TreeMap<K,V>) |
clear() Removes all entries from the ordered map. |
public readonly |
(boolean) |
containsKey(K key) Checks to see if the ordered map contains a key. |
public readonly |
(boolean) |
containsValue(V value) Checks to see if the ordered map contains a particular value. |
public readonly |
(TreeMap<K,V>) |
copy(AddressMap addresses) |
public |
(TreeMap<K,V>) |
deleteMax() Removes the largest key and associated value from the map. |
public |
(TreeMap<K,V>) |
deleteMin() Removes the smallest key and associated value from the ordered map. |
public readonly |
(nullable K) |
floor(K key) Returns the largest key in the ordered map less than or equal to the given key. |
public readonly |
(nullable V) |
index(K key) Retrieves the value associated with the key. |
public |
() |
index(K key, V value) Stores value object in the location associated with the key. |
public readonly |
(boolean) |
isEmpty() Checks whether or not the ordered map is empty. |
public readonly |
(Iterator<V>) |
iterator() Creates an iterator to iterate over all the values in the ordered map. |
public readonly |
(ArrayDeque<K>) |
keys() Returns a deque of all the keys in the ordered map. |
public readonly |
(ArrayDeque<K>) |
keys(K low, K high) Returns a deque containing all the keys in the ordered map in the given range. |
public readonly |
(K) |
max() Returns the largest key in the ordered map. |
public readonly |
(K) |
min() Returns the smallest key in the ordered map. |
public |
(nullable V) |
remove(K key) Removes the key-value pair associated with the key location. |
public readonly |
(String) |
toString() Produces a |
Modifiers | Return Types | Method and Description |
---|---|---|
public readonly get |
(int) |
size() Gets the number of key-value pairs in the ordered map as an |
public readonly get locked |
(long) |
sizeLong() Gets the number of key-value pairs in the ordered map as a |
public create() => ()
public destroy() => ()
public add(K key, V value) => (nullable V)
Stores value object in the location associated with the key and returns the old value if there was one at that location. This operation runs in logarithmic time.
key
- key location
value
- value to store
old value at location or null
if key was not already present
public readonly ceiling(K key) => (nullable K)
Returns the smallest key in the ordered map greater than or equal to the given key.
key
- key to compare against
smallest key in the ordered map less than or equal to key
public clear() => (TreeMap<K,V>)
Removes all entries from the ordered map.
ordered map after being cleared
public readonly containsKey(K key) => (boolean)
Checks to see if the ordered map contains a key. This operation runs in logarithmic time.
key
- key to find
true
if present
public readonly containsValue(V value) => (boolean)
Checks to see if the ordered map contains a particular value. This operation runs in time linear in the size of the tree.
value
- value to find
true
if present
public readonly copy(AddressMap addresses) => (TreeMap<K,V>)
public deleteMax() => (TreeMap<K,V>)
Removes the largest key and associated value from the map.
ordered map after deletion
NoSuchElementException
- if ordered map is empty
public deleteMin() => (TreeMap<K,V>)
Removes the smallest key and associated value from the ordered map.
ordered map after deletion
NoSuchElementException
- if ordered map is empty
public readonly floor(K key) => (nullable K)
Returns the largest key in the ordered map less than or equal to the given key.
key
- key to compare against
largest key in the ordered map less than or equal to key
public readonly index(K key) => (nullable V)
Retrieves the value associated with the key. If the key is not present, null
is returned. This operation runs in logarithmic time.
key
- key to find
value at key location or null
if not found
public index(K key, V value) => ()
Stores value object in the location associated with the key. This operation runs in logarithmic time.
key
- key location
value
- value to store
public readonly isEmpty() => (boolean)
Checks whether or not the ordered map is empty.
true
if the ordered map is empty
public readonly iterator() => (Iterator<V>)
Creates an iterator to iterate over all the values in the ordered map.
iterator
public readonly keys() => (ArrayDeque<K>)
Returns a deque of all the keys in the ordered map.
iterable collection of all keys
public readonly keys(K low, K high) => (ArrayDeque<K>)
Returns a deque containing all the keys in the ordered map in the given range.
low
- lowest possible key in the range
high
- highest possible key in the range
deque containing all keys between low
(inclusive) and high
(inclusive)
public readonly max() => (K)
Returns the largest key in the ordered map.
largest key
NoSuchElementException
- if the ordered map is empty
public readonly min() => (K)
Returns the smallest key in the ordered map.
smallest key
NoSuchElementException
- if the ordered map is empty
public remove(K key) => (nullable V)
Removes the key-value pair associated with the key location. This operation runs in logarithmic time.
key
- key to remove
value being removed or null
if not present
public readonly toString() => (String)
Produces a String
representation of the ordered map, listing all key-value pairs in an unspecified order.
String
representation