Skip to content
FutureBlitz

    Install

    Import std.collections.map

    std.collections.map

    Map<K, V>: a hash map from keys to values, in the order they were added. Its entries are in an array, each bucket starts a chain of the entries whose hashes land in it, and each entry links to the ones added before and after it, so removing one leaves the others in order. What a change takes out or replaces is let go of once the Map is whole again, so a key's or value's Destroy that it runs can use the Map.

    std/collections/map.fb

    Types

    Map class

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

    A hash map from keys to values, which keeps its entries in the order they were added.

    Examples

    Local ages = {"Ada": 36, "Alan": 41}
    ages["Grace"] = 85
    Expect(ages.Get("Ada") == 36)
    Expect(ages.Get("Bob") == Null)
    Expect(ages.Keys() == ["Ada", "Alan", "Grace"])

    std/collections/map.fb, line 31

    • Public New() constructor #

      A new, empty Map.

    • Public New(default: V) constructor #

      A Map whose [] gives value for a key that isn't there, without adding the key. It's one value, which every such read gives: a default that's an object or an array is shared, so to give each key one of its own, use GetOrAdd.

    • Public Property Count: Int property #

      How many entries it holds.

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

      Adds an entry, or gives an existing key its new value.

    • Public Method TryAdd(key: K, value: V): Bool method #

      Adds an entry when the key isn't there, and tells whether it wasn't.

    • Public Method AddAll(other: Map<K, V>) method #

      Adds each of other's entries, in its order, as Add does.

    • 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.

    • Public Method GetOrAdd(key: K, make: Func(): V): V method #

      The key's value, adding what make gives for it first when it isn't there, which is the key's value though make added the key itself.

    • Public Method Update(key: K, change: Func(V): V): Bool method #

      Gives the key's value what change gives for it, and tells whether the key was there. A key that change removed stays removed.

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

      The key's value. A key that isn't there gives the Map's default, without adding the key, or panics when the Map has none.

    • 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. The others keep their order.

    • @PanicsAtCaller Public Method RemoveWhere(test: Func(K, V): Bool): Int method #

      Removes each entry that test says to, and tells how many went.

    • Public Method Clear() method #

      Takes every entry out.

    • @PanicsAtCaller Public Method Reserve(count: Int) method #

      Makes room for count entries in all, so adding up to that many doesn't move them again.

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

      Its keys, in order, in a new array.

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

      Its values, in order, in a new array.

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

      A new, empty Map.

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

      A new Map with the same entries, in the same order, and the same default.

    • @PanicsAtCaller Public Method Filter(keep: Func(K, V): Bool): Map<K, V> method #

      A new Map of the entries that keep says to keep.

    • @PanicsAtCaller Public Method Find(test: Func(K, V): Bool): (K, V)? method #

      The first entry that test says is the one, or Null.

    • @PanicsAtCaller Public Method Any(test: Func(K, V): Bool): Bool method #

      Whether test says yes for any entry, going no further than the first.

    • @PanicsAtCaller Public Method MapValues<U>(change: Func(V): U): Map<K, U> method #

      A new Map of the same keys, in the same order, each with what change gives for its value.

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

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

    MapIterator struct

    Public Struct MapIterator<K: Hashable, V> Implements Iterator<(K, V)>

    The entries of a Map, as (key, value), in order, which For ... In goes over.

    std/collections/map.fb, line 405

    Extends

    Map extend

    Extend Map<K, V> Implements Equatable

    No doc comment.

    std/collections/map.fb, line 424

    Map extend

    Extend Map<K, V> Implements Hashable

    No doc comment.

    std/collections/map.fb, line 438

    Map extend

    Extend Map<K, V> Implements Printable

    No doc comment.

    std/collections/map.fb, line 451

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