Skip to content
FutureBlitz

    Install

    Import std.collections.sorted

    SortedMap

    std.collections.sorted

    class

    @DebugEntries Public Class SortedMap<K: Comparable, V> Implements Iterable<(K, V)>, Cloneable, Defaultable

    A Map that keeps its keys in order, smallest first, for ranges and the nearest key to another.

    Examples

    Local grades = SortedMap<Int, String>()
    grades.Add(90, "A")
    grades.Add(70, "C")
    grades.Add(80, "B")
    Expect(grades.Keys() == [70, 80, 90])
    Expect(grades.Floor(85) == (80, "B"))
    Expect(grades.Ceiling(85) == (90, "A"))
    Expect(grades.Range(70, 90) == [(70, "C"), (80, "B")])

    std/collections/sorted.fb, line 58

    • Public New() constructor #

      A new, empty SortedMap.

    • Public Property Count: Int property #

      How many entries it holds.

    • @PanicsAtCaller Public Method Add(key: K, value: V) method #

      Adds an entry, or gives an existing key its new value, which leaves the tree as it is. A key that isn't equal to itself, like NaN, panics.

    • Public Method Get(key: K): V? method #

      The key's value, or Null when it isn't there.

    • Public Method Get(key: K, fallback: V): V method #

      The key's value, or fallback when it isn't there.

    • @PanicsAtCaller Operator [](key: K): V operator #

      The key's value. A key that isn't there panics.

    • @PanicsAtCaller Operator []=(key: K, value: V) operator #

      Gives the key a value, adding it when it isn't there.

    • Public Method Contains(key: K): Bool method #

      Whether key has an entry.

    • Public Method Remove(key: K): Bool method #

      Removes the key's entry, and tells whether there was one. A key that isn't there leaves the tree as it is.

    • Public Method Clear() method #

      Takes every entry out.

    • Public Method First(): (K, V)? method #

      The smallest key and its value, or Null when there's none.

    • Public Method Last(): (K, V)? method #

      The largest key and its value, or Null when there's none.

    • Public Method Floor(key: K): (K, V)? method #

      The largest key that isn't above key, and its value, or Null when there's none, as for a key that isn't equal to itself.

    • Public Method Ceiling(key: K): (K, V)? method #

      The smallest key that isn't below key, and its value, or Null when there's none, as for a key that isn't equal to itself.

    • Public Method Range(low: K, high: K): (K, V)[] method #

      The entries from low up to high, without high itself, in order, in a new array. An end that isn't equal to itself finds none.

    • Public Method Keys(): K[] method #

      The keys, in order.

    • Public Method Values(): V[] method #

      The values, in their keys' order.

    • Public Static Method DefaultValue(): SortedMap<K, V> static method #

      A new, empty SortedMap.

    • Public Method Clone(): SortedMap<K, V> method #

      A new SortedMap with the same entries.

    • Public Method Iterate(): SortedMapIterator<K, V> method #

      Each key and its value, in order, for 'For key, value In map'. Giving a key a new value while going over them is fine, but adding or removing one panics.

    Report an issue with this page or with FutureBlitz on GitHub.