TreeMap

constructor()

Constructs a new, empty tree map, using the natural ordering of its keys. All keys inserted into the map must implement the Comparable interface and be mutually comparable.


constructor(comparator: Comparator<K>?)

Constructs a new, empty tree map, ordered according to the given comparator. All keys inserted into the map must be mutually comparable by the given comparator.

Parameters

comparator

the comparator that will be used to order this map. If null, the natural ordering of the keys will be used.


constructor(m: Map<out K, V>)

Constructs a new tree map containing the same mappings as the given map, ordered according to the natural ordering of its keys. Requires keys to be Comparable. Runs in n*log(n) time.

Parameters

m

the map whose mappings are to be placed in this map

Throws

if the keys in m are not Comparable or are not mutually comparable.

if the specified map is null.


constructor(m: TreeMap<K, out V>)

Constructs a new tree map containing the same mappings and using the same ordering as the specified sorted map (approximated by checking if the input map is also a TreeMap with the same comparator). If compatible, this method runs in linear time (O(n)). Otherwise, it falls back to O(n log n).

Parameters

m

the sorted map whose mappings are to be placed in this map, and whose comparator is potentially used to sort this map.

Throws

if the specified map is null.