javascript-collections-framework
    Preparing search index...

    Interface ReadonlySortedMap<K, V>

    The read-only view of a sorted map: a map whose mappings are kept in the order of its keys under a comparator, with the first and last entries, the entries nearest a key and live range views. Two keys are the same key when the comparator returns 0 for them.

    "Before" and "after" follow the map's own order, which is descending on a reversed view. Questions about keys alone go through keySet(), a sorted set: map.keySet().floor(k). A sorted map is a sequenced map whose order is decided by its keys.

    function priceAt(levels: ReadonlySortedMap<number, string>, at: number): string | undefined {
    return levels.floorEntry(at)?.value
    }
    interface ReadonlySortedMap<K, V> {
        revision: number;
        size: number;
        "[equalsSymbol]"(other: unknown): boolean;
        "[hashCodeSymbol]"(hash: HashFunction): number;
        "[iterator]"(): IterableIterator<[K, V]>;
        ceilingEntry(key: K): MapEntry<K, V> | undefined;
        comparator(): Comparator<K> | undefined;
        containsValue(value: V): boolean;
        entries(): IterableIterator<[K, V]>;
        entrySet(): ReadonlySequencedSet<MapEntry<K, V>>;
        equals(other: unknown): boolean;
        firstEntry(): MapEntry<K, V> | undefined;
        floorEntry(key: K): MapEntry<K, V> | undefined;
        forEach(
            action: (value: V, key: K, map: ReadonlyMapCollection<K, V>) => void,
            thisArg?: unknown,
        ): void;
        get(key: K): V | undefined;
        getOrDefault<D>(key: K, fallback: D): V | D;
        has(key: K): boolean;
        headMap(to: K, options?: BoundOptions | null): ReadonlySortedMap<K, V>;
        higherEntry(key: K): MapEntry<K, V> | undefined;
        isEmpty(): boolean;
        keys(): IterableIterator<K>;
        keySet(): ReadonlySortedSet<K>;
        lastEntry(): MapEntry<K, V> | undefined;
        lowerEntry(key: K): MapEntry<K, V> | undefined;
        reversed(): ReadonlySortedMap<K, V>;
        subMap(
            from: K,
            to: K,
            options?: SubSetOptions | null,
        ): ReadonlySortedMap<K, V>;
        tailMap(from: K, options?: BoundOptions | null): ReadonlySortedMap<K, V>;
        toJSON(): [K, V][];
        toString(): string;
        valueCollection(): ReadonlySequencedCollection<V>;
        values(): IterableIterator<V>;
    }

    Type Parameters

    • K
    • V

    Hierarchy (View Summary)

    Index
    revision: number

    A number that changes on every change to the mappings — adding or removing one, or writing a value — and never on a read, except that a read moving a mapping of an access-ordered map changes it too. Its exact values are unspecified. Time: O(1).

    size: number

    The number of mappings. Time: O(1) on a map; O(k + log n) on a range view holding k of the map's n mappings, which counts the mappings in range.

    • The value-equality protocol; delegates to equals. Time: as equals.

      Parameters

      • other: unknown

      Returns boolean

    • Returns an iterator over new [key, value] arrays in key order.

      Time: O(log n) to create; O(1) amortised per step.

      Returns IterableIterator<[K, V]>

      A new iterator.

      ConcurrentModificationError (from next()) when mappings are added or removed after the iterator is created.

    • Returns the entry of the least key equal to or after key, or undefined when there is none.

      Time: O(log n).

      Parameters

      • key: K

        The key to search from; it need not be present.

      Returns MapEntry<K, V> | undefined

      A live entry, or undefined.

    • Returns the comparator that orders the keys, or undefined for natural order; a reversed view returns a function that orders in reverse.

      Time: O(1).

      Returns Comparator<K> | undefined

      The comparator, or undefined.

    • Returns whether some value is SameValueZero-equal to value.

      Time: O(n).

      Parameters

      • value: V

        The value to look for.

      Returns boolean

      true when a mapping has that value.

    • Returns an iterator over new [key, value] arrays in key order.

      Time: O(log n) to create; O(1) amortised per step.

      Returns IterableIterator<[K, V]>

      A new iterator.

    • Returns whether other is a map with the same size that maps every key of this map to an equal value, and whose keys this map all maps to equal values.

      Time: as the map documents — O(n) average for a HashMap, O(n log n) for a TreeMap — plus the protocol methods.

      Parameters

      • other: unknown

        Any value.

      Returns boolean

      true when other is an equal map.

    • Returns the entry of the greatest key equal to or before key, or undefined when there is none.

      Time: O(log n).

      Parameters

      • key: K

        The key to search from; it need not be present.

      Returns MapEntry<K, V> | undefined

      A live entry, or undefined.

    • Calls action(value, key, map) for each mapping in order, with this set to thisArg.

      Time: O(n) plus the calls.

      Parameters

      • action: (value: V, key: K, map: ReadonlyMapCollection<K, V>) => void

        Called with each value, its key and the map.

      • OptionalthisArg: unknown

        The this value for action.

      Returns void

      TypeError when action is not a function.

    • Returns the value mapped to a key equal to key, or undefined when there is none.

      Time: as the implementation documents.

      Parameters

      • key: K

        The key to look up.

      Returns V | undefined

      The value, or undefined.

    • Returns the value mapped to key when the key is present (even when that value is undefined), and fallback otherwise.

      Time: as get.

      Type Parameters

      • D

      Parameters

      • key: K

        The key to look up.

      • fallback: D

        The value to return when the key is absent.

      Returns V | D

      The mapped value, or fallback.

    • Returns whether a key equal to key is present.

      Time: as get.

      Parameters

      • key: K

        The key to look for.

      Returns boolean

      true when the key is present.

    • Returns a live view of the mappings whose keys are before to (exclusive by default).

      Time: O(log n).

      Parameters

      • to: K

        The high end, in this map's order.

      • Optionaloptions: BoundOptions | null

        The inclusive flag.

      Returns ReadonlySortedMap<K, V>

      The view.

    • Returns the entry of the least key after key, or undefined when there is none.

      Time: O(log n).

      Parameters

      • key: K

        The key to search from; it need not be present.

      Returns MapEntry<K, V> | undefined

      A live entry, or undefined.

    • Returns whether there are no mappings.

      Time: O(1) on a map; O(log n) on a range view, which looks for one mapping in range.

      Returns boolean

      size === 0.

    • Returns an iterator over the keys in order.

      Time: O(log n) to create; O(1) amortised per step.

      Returns IterableIterator<K>

      A new iterator.

    • Returns the entry of the greatest key before key, or undefined when there is none.

      Time: O(log n).

      Parameters

      • key: K

        The key to search from; it need not be present.

      Returns MapEntry<K, V> | undefined

      A live entry, or undefined.

    • Returns a live view of the mappings whose keys run from from (inclusive by default) to to (exclusive by default).

      Time: O(log n).

      Parameters

      • from: K

        The low end, in this map's order.

      • to: K

        The high end, in this map's order.

      • Optionaloptions: SubSetOptions | null

        The inclusive flags.

      Returns ReadonlySortedMap<K, V>

      The view.

    • Returns a live view of the mappings whose keys are from (inclusive by default) or after it.

      Time: O(log n).

      Parameters

      • from: K

        The low end, in this map's order.

      • Optionaloptions: BoundOptions | null

        The inclusive flag.

      Returns ReadonlySortedMap<K, V>

      The view.

    • Returns a new array of [key, value] arrays, so JSON.stringify writes the map as pairs.

      Time: O(n).

      Returns [K, V][]

      A new array.

    • Returns the class name, size and mappings, e.g. HashMap(1) {'a' => 1}.

      Time: O(length of the output) for flat contents.

      Returns string

      The text.

    • Returns an iterator over the values in key order.

      Time: O(log n) to create; O(1) amortised per step.

      Returns IterableIterator<V>

      A new iterator.