shadow:utility

Class TreeMap<K,V>

Parent class

shadow:standard@Object

Interfaces

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.

See Also

Create Summary

Modifiers Return Types Method and Description
public () create()

Destroy Summary

Modifiers Return Types Method and Description
public () destroy()

Method Summary

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 String representation of the ordered map, listing all key-value pairs in an unspecified order.

Property Summary

Modifiers Return Types Method and Description
public readonly get (int) size()

Gets the number of key-value pairs in the ordered map as an int.

public readonly get locked (long) sizeLong()

Gets the number of key-value pairs in the ordered map as a long.

Create Detail

create

public create() => ()

Destroy Detail

destroy

public destroy() => ()

Method Detail

add

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.

Parameters

key - key location

value - value to store

Returns

old value at location or null if key was not already present

ceiling

public readonly ceiling(K key) => (nullable K)

Returns the smallest key in the ordered map greater than or equal to the given key.

Parameters

key - key to compare against

Returns

smallest key in the ordered map less than or equal to key

clear

public clear() => (TreeMap<K,V>)

Removes all entries from the ordered map.

Returns

ordered map after being cleared

containsKey

public readonly containsKey(K key) => (boolean)

Checks to see if the ordered map contains a key. This operation runs in logarithmic time.

Parameters

key - key to find

Returns

true if present

containsValue

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.

Parameters

value - value to find

Returns

true if present

copy

public readonly copy(AddressMap addresses) => (TreeMap<K,V>)

deleteMax

public deleteMax() => (TreeMap<K,V>)

Removes the largest key and associated value from the map.

Returns

ordered map after deletion

Throws

NoSuchElementException - if ordered map is empty

deleteMin

public deleteMin() => (TreeMap<K,V>)

Removes the smallest key and associated value from the ordered map.

Returns

ordered map after deletion

Throws

NoSuchElementException - if ordered map is empty

floor

public readonly floor(K key) => (nullable K)

Returns the largest key in the ordered map less than or equal to the given key.

Parameters

key - key to compare against

Returns

largest key in the ordered map less than or equal to key

index

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.

Parameters

key - key to find

Returns

value at key location or null if not found

index

public index(K key, V value) => ()

Stores value object in the location associated with the key. This operation runs in logarithmic time.

Parameters

key - key location

value - value to store

isEmpty

public readonly isEmpty() => (boolean)

Checks whether or not the ordered map is empty.

Returns

true if the ordered map is empty

iterator

public readonly iterator() => (Iterator<V>)

Creates an iterator to iterate over all the values in the ordered map.

Returns

iterator

keys

public readonly keys() => (ArrayDeque<K>)

Returns a deque of all the keys in the ordered map.

Returns

iterable collection of all keys

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.

Parameters

low - lowest possible key in the range

high - highest possible key in the range

Returns

deque containing all keys between low (inclusive) and high (inclusive)

max

public readonly max() => (K)

Returns the largest key in the ordered map.

Returns

largest key

Throws

NoSuchElementException - if the ordered map is empty

min

public readonly min() => (K)

Returns the smallest key in the ordered map.

Returns

smallest key

Throws

NoSuchElementException - if the ordered map is empty

remove

public remove(K key) => (nullable V)

Removes the key-value pair associated with the key location. This operation runs in logarithmic time.

Parameters

key - key to remove

Returns

value being removed or null if not present

toString

public readonly toString() => (String)

Produces a String representation of the ordered map, listing all key-value pairs in an unspecified order.

Returns

String representation

Property Detail

size

public readonly get size() => (int)

Gets the number of key-value pairs in the ordered map as an int.

sizeLong

public readonly get locked sizeLong() => (long)

Gets the number of key-value pairs in the ordered map as a long.