Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/froebel/ds.ts>SortedMap

A strictly typed utility library.
Go to Latest
class SortedMap
implements Map<K, V>
import { SortedMap } from "https://deno.land/x/froebel@v0.21.3/ds.ts";

Behaves like a regular JavaScript Map, but its iteration order is dependant on the compare function supplied in the constructor.

Note: The item's sort position is only computed automatically on insertion. If you update one of the values that the compare function depends on, you must call the update(key) method afterwards to ensure the map stays sorted.

Constructors

new
SortedMap(compare: Cmp<K, V>, entries?: readonly (readonly [K, V])[] | null)

Properties

clear
entries: () => unknown
get
has
keys: () => unknown
readonly
size
values: () => unknown
[Symbol.iterator]: () => unknown
[Symbol.toStringTag]

Methods

delete(key: K)
forEach(callback: (
value: V,
key: K,
map: SortedMap<K, V>,
) => void
)
map<T>(callback: (
value: V,
key: K,
map: SortedMap<K, V>,
) => T
): T[]
set(key: K, value: V): this
update(key: K)

Update the sort position of the element at key if necessary.

This method should be called to notify the SortedMap that one of the parameters that the compare function depends on has been updated and consequently the sort order must be verified/updated.