Skip to content
FutureBlitz

    Install

    Import std.collections.multi_map

    std.collections.multi_map

    A map from each key to one value or more.

    MultiMap<K, V>: keys that each have one value or more, in the order they were added: a Map from each key to an array of its values, in the order they were added too. A key whose last value goes, goes.

    std/collections/multi_map.fb

    Types

    MultiMap class

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

    A Map from each key to any number of values, in the order they were added.

    Examples

    Local tags = MultiMap<String, String>()
    tags.Add("fruit", "apple")
    tags.Add("fruit", "pear")
    tags.Add("veg", "leek")
    Expect(tags.Get("fruit") == ["apple", "pear"])
    Expect(tags.Count == 3 && tags.KeyCount == 2)
    Expect(tags.Get("nuts").Count == 0)

    std/collections/multi_map.fb, line 24

    • Public New() constructor #

      A new, empty MultiMap.

    • Public Property Count: Int property #

      How many values it has, of all the keys.

    • Public Property KeyCount: Int property #

      How many keys have values.

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

      Adds a value for the key, after the ones it has.

    • Public Method AddAll(key: K, values: Iterable<V>) method #

      Adds each of the values for the key, in order, all read first.

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

      The key's values, in the order they were added, in a new array, which is empty when the key has none.

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

      The same as Get.

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

      Whether key has any values.

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

      Whether the key has the value.

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

      Removes the first of the key's values that's equal to value, and tells whether there was one.

    • Public Method RemoveKey(key: K): Int method #

      Removes the key and all its values, and gives how many values went.

    • Public Method Clear() method #

      Takes every key and value out.

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

      The keys that have values, in the order they were added.

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

      A new, empty MultiMap.

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

      A new MultiMap with the same keys and values.

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

      Each key with each of its values, for 'For key, value In multi', the keys in the order they were added and each one's values in theirs. Adding or removing a value while going over them panics.

    MultiMapIterator struct

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

    The entries of a MultiMap, as (key, value), a key's values in order, which a For loop goes over.

    std/collections/multi_map.fb, line 130

    • @PanicsAtCaller Public ByRef Method Next(): (K, V)? method #

      The next key with one of its values, the keys in the order they were added and each one's values in theirs, or Null after the last. Panics when the MultiMap changed since the loop began.

    Extends

    MultiMap extend

    Extend MultiMap<K, V> Implements Equatable

    Compares MultiMaps with == and !=, where their values can be compared.

    std/collections/multi_map.fb, line 163

    • Operator ==(a: MultiMap<K, V>, b: MultiMap<K, V>): Bool operator #

      Whether the two have the same keys, each with equal values in the same order.

    MultiMap extend

    Extend MultiMap<K, V> Implements Printable

    Shows a MultiMap in a string, as its ToString writes it.

    std/collections/multi_map.fb, line 172

    • Public Method ToString(): String method #

      Each key and its values, as {fruit: [apple, pear], veg: [leek]}.

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