SortedMap
classin packageklyn.collections
public class SortedMap<K, V> extends Object implements Map<K, V>:
└ SortedMap
All Implemented Interfaces: Map

Mutable map that traverses entries in ascending key order.

The runtime uses a balanced binary search tree, giving logarithmic lookup, insertion and removal. Use the t:{...} literal when the ordering guarantee is required; prefer HashMap for average constant-time key access.

Native operator mapping:

  • operator[] is mapped to klyn_collections_Map_operator_index.
  • operator== is mapped to klyn_collections_Map_operator_eq.
  • operator!= is mapped to klyn_collections_Map_operator_ne.
Example
import klyn.collections

values = t:{3: "three", 1: "one", 2: "two"}
assert values.keys() == i:[1, 2, 3]
Properties
Modifier and Type Member Description
public readonly native property size
size as ULong
Gets the number of entries.
Inherited Properties
propertyInherited Properties from Object: type
propertyInherited Properties from Map: size
Constructors
Modifier and Type Member Description
public SortedMap Creates an empty sorted map.
public SortedMap
SortedMap(keys as IList<K>, values as IList<V>):
Creates a sorted map from corresponding key and value lists.
public SortedMap
SortedMap(map as Map<K, V>):
Creates a sorted map containing another map's entries.
Methods
Modifier and Type Member Description
public native clear
clear() as Void
Removes every entry.
public native containsValue
containsValue(value as V) as Boolean
Returns whether the map contains a value.
public get
get<R>(key as K, defaultValue as R) as R:
Returns the associated value or a typed default when the key is absent.
public native items
items() as IList<Tuple<K, V> >
Returns key-value tuples in ascending key order.
public native keys
keys() as IList<K>
Returns keys in ascending order.
public native remove
remove(key as K) as Boolean
Removes an entry.
public native override toString
toString() as String
Returns the t:{...} representation of the sorted map.
public native values
values() as IList<V>
Returns values in ascending key order.
Inherited Methods
methodInherited Methods from Object: deepCopy, fromJson, hash, toDict, toJson, toString, toXml
methodInherited Methods from Map: clear, containsValue, get, items, keys, remove, values
Operators
Modifier and Type Member Description
public native operator in(key as K) as Boolean Returns whether the map contains a key.
public native static operator!=(readonly notnull left as SortedMap, readonly notnull right as SortedMap) as Boolean Compares two sorted maps structurally for inequality.
public native static operator==(readonly notnull left as SortedMap, readonly notnull right as SortedMap) as Boolean Compares two sorted maps structurally.
public native operator[](key as K) as V Gets or sets the value associated with a key.
Inherited Operators
operatorInherited Operators from Map: operator in(key as K) as Boolean, operator[](key as K) as V