Skip to main content

interface OrderedHashMap<K,V>

A type-invariant immutable Ordered HashMap of key type K, and value type V. In the Map, each key has exactly one value, and the Map cannot contain duplicate keys. See the Map documentation and the OrderedHashMap API documentation

Companion namespace: OrderedHashMap

Extends: OrderedMapBase<K,V,Tp>

Implemented by: OrderedHashMap.NonEmpty<K,V>

Type parameters

NameDescription
Kthe key type
Vthe value type
note
  • The OrderedHashMap keeps the insertion order of elements, thus iterators and streams will also reflect this order. - The OrderedHashMap wraps around a HashMap instance, thus has mostly the same time complexity as the HashMap. - The OrderedHashMap keeps the key insertion order in a List, thus its space complexity is higher than a regular HashMap.
example
const m1 = OrderedHashMap.empty<number, string>()
const m2 = OrderedHashMap.of([1, 'a'], [2, 'b'])

Properties

keyOrder

Returns a List instance containing the key order of the Map.

Definition

readonly keyOrder: List<K>;

example
const m = OrderedHashMap.of([2, 'b'], [1, 'a'], [3, 'c'])
console.log(m.keyOrder.toArray())
// => [2, 1, 3]

Overrides

OrderedMapBase.keyOrder

sourceMap

Returns the contained Map instance.

Definition

readonly sourceMap: WithKeyValue<Tp, K, V>['sourceMap'];

example
const m = OrderedHashMap.of([2, 'b'], [1, 'a'])
console.log(m.sourceMap.toString())
// => HashMap(1 -> 'a', 2 -> 'b')

Overrides

OrderedMapBase.sourceMap