moonbitstack/moonstl/map does not have a README file

    FlatMultiSet

    type FlatMultiSet[K] = FlatMultiMap[K, Unit]

    A flat multiset keeps repeats in sorted order and counts them.

    MultiSet

    type MultiSet[K] = MultiMap[K, Unit]

    A multiset is a multimap whose values carry no information.

    SortedMultiSet

    type SortedMultiSet[K] = SortedMultiMap[K, Unit]

    A sorted multiset is a sorted multimap whose values carry no information.

    BiMap

    pub struct BiMap[K, V] {
    forward : IndexMap[K, V]
    backward : IndexMap[V, K]
    }

    A two-way map: the pair k -> v can be read from either side, and neither a key nor a value can appear twice. set keeps the mapping total by dropping whatever the new pair collides with, and hands it back.

    test {
    let bimap : @map.BiMap[Int32, String] = @map.BiMap::new()
    let _ = bimap.set(1, "a")
    let _ = bimap.set(2, "b")
    @test.assert_eq(bimap.get_key("b"), Some(2))
    @test.assert_eq(bimap.set(1, "b"), Some((1, "a")))
    @test.assert_eq(bimap.get(1), Some("b"))
    @test.assert_eq(bimap.get(2), None)
    }
    impl Eq for BiMap[K, V]
    impl Show for BiMap[K, V]

    BiMap::clear

    fn[K, V] BiMap::clear(self : BiMap[K, V]) -> Unit

    Removes every pair from both sides.

    BiMap::contains_key

    fn[K : Hash + Eq, V] BiMap::contains_key(self : BiMap[K, V], key : K) -> Bool

    Whether key is on the key side.

    BiMap::contains_value

    fn[K, V : Hash + Eq] BiMap::contains_value(self : BiMap[K, V], value : V) -> Bool

    Whether value is on the value side.

    BiMap::copy

    fn[K, V] BiMap::copy(self : BiMap[K, V]) -> BiMap[K, V]

    A copy that owns both tables: a change to either bijection is invisible to the other.

    BiMap::equal

    fn[K : Eq, V : Eq] BiMap::equal(self : BiMap[K, V], other : BiMap[K, V]) -> Bool

    BiMap::get

    fn[K : Hash + Eq, V] BiMap::get(self : BiMap[K, V], key : K) -> V?

    The value key is mapped to, or None.

    BiMap::get_key

    fn[K, V : Hash + Eq] BiMap::get_key(self : BiMap[K, V], value : V) -> K?

    The key a value belongs to, which is the reverse of get.

    BiMap::is_empty

    fn[K, V] BiMap::is_empty(self : BiMap[K, V]) -> Bool

    Whether the bijection holds no pair.

    BiMap::iter

    fn[K, V] BiMap::iter(self : BiMap[K, V]) -> Iter[(K, V)]

    The pairs in insertion order.

    BiMap::keys

    fn[K, V] BiMap::keys(self : BiMap[K, V]) -> Iter[K]

    The keys in insertion order.

    BiMap::length

    fn[K, V] BiMap::length(self : BiMap[K, V]) -> Int

    How many pairs the bijection holds.

    BiMap::new

    fn[K, V] BiMap::new(capacity? : Int, hash_seed? : Int) -> BiMap[K, V]

    An empty bijection, with room for capacity pairs and its tables laid out from hash_seed.

    BiMap::not_equal

    fn[K : Eq, V : Eq] BiMap::not_equal(x : BiMap[K, V], y : BiMap[K, V]) -> Bool

    BiMap::output

    fn[K : Show, V : Show] BiMap::output(self : BiMap[K, V], logger : &Logger) -> Unit

    BiMap::remove_key

    fn[K : Hash + Eq, V : Hash + Eq] BiMap::remove_key(self : BiMap[K, V], key : K) -> (K, V)?

    Removes the pair whose key is key from both sides and returns it.

    BiMap::remove_value

    fn[K : Hash + Eq, V : Hash + Eq] BiMap::remove_value(self : BiMap[K, V], value : V) -> (K, V)?

    Removes the pair whose value is value from both sides and returns it.

    BiMap::set

    fn[K : Hash + Eq, V : Hash + Eq] BiMap::set(self : BiMap[K, V], key : K, value : V) -> (K, V)?

    Stores the pair, dropping the pair the key belonged to and the pair the value belonged to, and returns one of the dropped pairs — the one the key displaced when there is one, otherwise the one the value displaced.

    BiMap::set_new

    fn[K : Hash + Eq, V : Hash + Eq] BiMap::set_new(self : BiMap[K, V], key : K, value : V) -> Unit raise
    Refused

    Stores the pair only when neither side is taken, and refuses otherwise.

    BiMap::to_string

    fn[K : Show, V : Show] BiMap::to_string(self : BiMap[K, V]) -> String

    BiMap::values

    fn[K, V] BiMap::values(self : BiMap[K, V]) -> Iter[V]

    The values, in the order their keys were inserted.

    ChainMap

    pub struct ChainMap[K, V] {
    chain : Array[Map[K, V]]
    }

    A stack of maps read as one: a lookup falls through the stack from the front, and a write always lands in the front map. That is what a layered configuration needs — a child scope that sees its parent's settings but shadows them without touching them.

    test {
    let base : Map[String, Int32] = Map([])
    base.set("a", 1)
    let chain : @map.ChainMap[String, Int32] = @map.ChainMap::new([base])
    @test.assert_eq(chain.get("a"), Some(1))
    let child = chain.new_child()
    child.set("a", 2)
    @test.assert_eq(child.get("a"), Some(2))
    @test.assert_eq(chain.get("a"), Some(1))
    }

    ChainMap::contains

    fn[K : Hash + Eq, V] ChainMap::contains(self : ChainMap[K, V], key : K) -> Bool

    Whether any map in the chain holds key.

    ChainMap::copy

    fn[K, V] ChainMap::copy(self : ChainMap[K, V]) -> ChainMap[K, V]

    A copy whose maps are copies: a write through it leaves the original chain alone.

    ChainMap::flatten

    fn[K : Hash + Eq, V] ChainMap::flatten(self : ChainMap[K, V]) -> Map[K, V]

    Copies the chain into one map, which is what a child does when it has to stop following its parent.

    ChainMap::get

    fn[K : Hash + Eq, V] ChainMap::get(self : ChainMap[K, V], key : K) -> V?

    The value of key from the first map in the chain that holds it.

    ChainMap::iter

    fn[K : Hash + Eq, V] ChainMap::iter(self : ChainMap[K, V]) -> Iter[(K, V)]

    Every pair the chain answers for: the first map that holds a key decides its value.

    ChainMap::length

    fn[K : Hash + Eq, V] ChainMap::length(self : ChainMap[K, V]) -> Int

    The number of distinct keys the chain answers for.

    ChainMap::maps

    fn[K, V] ChainMap::maps(self : ChainMap[K, V]) -> Array[Map[K, V]]

    The maps of the chain, front first.

    ChainMap::new

    fn[K, V] ChainMap::new(maps : Array[Map[K, V]]) -> ChainMap[K, V]

    Builds a chain over maps, the first of which is written to.

    ChainMap::new_child

    fn[K : Hash + Eq, V] ChainMap::new_child(self : ChainMap[K, V]) -> ChainMap[K, V]

    Puts a fresh empty map in front, which is how a narrower scope is opened.

    ChainMap::parent

    fn[K, V] ChainMap::parent(self : ChainMap[K, V]) -> ChainMap[K, V]?

    The chain without its front map, or None when only one is left.

    ChainMap::remove

    fn[K : Hash + Eq, V] ChainMap::remove(self : ChainMap[K, V], key : K) -> Unit

    Removes key from every map in the chain, so a shadowed value does not reappear once the front one is dropped.

    ChainMap::set

    fn[K : Hash + Eq, V] ChainMap::set(self : ChainMap[K, V], key : K, value : V) -> Unit

    Writes into the front map, which is the only map a chain ever changes.

    Counter

    pub struct Counter[K] {
    map : IndexMap[K, Int]
    total_count : Int64
    }

    A multiset of counts: each key carries how many times it was seen, and a key whose count reaches zero leaves the counter so that iteration only ever sees keys that are present.

    test {
    let counter : @map.Counter[String] = @map.Counter::new()
    @test.assert_eq(counter.incr("a"), 1)
    @test.assert_eq(counter.incr_by("a", 2), 3)
    @test.assert_eq(counter.decr("a"), 2)
    @test.assert_eq(counter.total(), 2L)
    }
    impl Eq for Counter[K]
    impl Show for Counter[K]

    Counter::add

    fn[K : Hash + Eq] Counter::add(self : Counter[K], other : Counter[K]) -> Counter[K]

    The sum of two counters, as a new one. The keys keep the order of self, and keys only other has follow.

    Counter::clear

    fn[K] Counter::clear(self : Counter[K]) -> Unit

    Drops every key and its count.

    Counter::copy

    fn[K] Counter::copy(self : Counter[K]) -> Counter[K]

    A copy that owns its table: a change to either counter is invisible to the other.

    Counter::decr

    fn[K : Hash + Eq] Counter::decr(self : Counter[K], key : K) -> Int

    Subtracts one from key's count and drops the key once its count reaches zero, returning the count it holds afterwards.

    Counter::decr_by

    fn[K : Hash + Eq] Counter::decr_by(self : Counter[K], key : K, amount : Int) -> Int

    Subtracts amount from key's count and drops the key once its count reaches zero or below, returning the count it holds afterwards.

    Counter::elements

    fn[K] Counter::elements(self : Counter[K]) -> Iter[K]

    Every key repeated as many times as it was counted.

    Counter::equal

    fn[K : Eq] Counter::equal(self : Counter[K], other : Counter[K]) -> Bool

    Counter::get

    fn[K : Hash + Eq] Counter::get(self : Counter[K], key : K) -> Int

    The count of key, zero when it has none.

    Counter::incr

    fn[K : Hash + Eq] Counter::incr(self : Counter[K], key : K) -> Int

    Adds one and returns the new count.

    Counter::incr_by

    fn[K : Hash + Eq] Counter::incr_by(self : Counter[K], key : K, amount : Int) -> Int

    Adds amount, which may be negative, and returns the new count. A count that reaches zero or below removes the key.

    Counter::is_empty

    fn[K] Counter::is_empty(self : Counter[K]) -> Bool

    Whether no key is counted.

    Counter::iter

    fn[K] Counter::iter(self : Counter[K]) -> Iter[(K, Int)]

    The keys and their counts in insertion order.

    Counter::keys

    fn[K] Counter::keys(self : Counter[K]) -> Iter[K]

    The keys in insertion order.

    Counter::length

    fn[K] Counter::length(self : Counter[K]) -> Int

    The number of distinct keys counted.

    Counter::most_common

    fn[K] Counter::most_common(self : Counter[K], n~ : Int) -> Array[(K, Int)]

    The n keys with the largest counts, ties in insertion order. n below zero means every key.

    Counter::new

    fn[K] Counter::new(capacity? : Int, hash_seed? : Int) -> Counter[K]

    A counter with room for capacity keys, laid out from hash_seed.

    Counter::not_equal

    fn[K : Eq] Counter::not_equal(x : Counter[K], y : Counter[K]) -> Bool

    Counter::output

    fn[K : Show] Counter::output(self : Counter[K], logger : &Logger) -> Unit

    Counter::retain

    fn[K : Hash + Eq] Counter::retain(self : Counter[K], f : (K, Int) -> Bool) -> Unit

    Keeps the keys f accepts with their counts and drops the rest.

    Counter::subtract_in_place

    fn[K : Hash + Eq] Counter::subtract_in_place(self : Counter[K], other : Counter[K]) -> Unit

    Subtracts other from this counter in place, dropping keys that reach zero.

    Counter::to_array

    fn[K] Counter::to_array(self : Counter[K]) -> Array[(K, Int)]

    The keys and their counts in insertion order, as a new array.

    Counter::to_string

    fn[K : Show] Counter::to_string(self : Counter[K]) -> String

    Counter::total

    fn[K] Counter::total(self : Counter[K]) -> Int64

    The sum of every count.

    DefaultMap

    pub struct DefaultMap[K, V] {
    map : IndexMap[K, V]
    factory : (K) -> V
    }

    A map that answers a lookup with a value it makes up on the spot: the factory is called with the key, so a reader never has to write the check-then-insert pair by hand.

    test {
    let map : @map.DefaultMap[String, Int32] = @map.DefaultMap::new(factory=key => {
    key.length()
    })
    @test.assert_eq(map.get_or_init("abc"), 3)
    @test.assert_eq(map.length(), 1)
    @test.assert_eq(map.get("abc"), Some(3))
    }
    impl Eq for DefaultMap[K, V]
    impl Show for DefaultMap[K, V]

    DefaultMap::clear

    fn[K, V] DefaultMap::clear(self : DefaultMap[K, V]) -> Unit

    Removes every entry, keeping the factory.

    DefaultMap::contains

    fn[K : Hash + Eq, V] DefaultMap::contains(self : DefaultMap[K, V], key : K) -> Bool

    Whether key has an entry; a key the factory would answer still reads as absent until it is stored.

    DefaultMap::copy

    fn[K, V] DefaultMap::copy(self : DefaultMap[K, V]) -> DefaultMap[K, V]

    A copy that owns its table and shares the factory: a change to either map is invisible to the other.

    DefaultMap::equal

    fn[K : Eq, V : Eq] DefaultMap::equal(self : DefaultMap[K, V], other : DefaultMap[K, V]) -> Bool

    DefaultMap::get

    fn[K : Hash + Eq, V] DefaultMap::get(self : DefaultMap[K, V], key : K) -> V?

    The value under key, or None; unlike get_or_init this does not call the factory and stores nothing.

    DefaultMap::get_or_init

    fn[K : Hash + Eq, V] DefaultMap::get_or_init(self : DefaultMap[K, V], key : K) -> V

    The value under key, inserting factory(key) when the key is new.

    DefaultMap::is_empty

    fn[K, V] DefaultMap::is_empty(self : DefaultMap[K, V]) -> Bool

    Whether the map holds no entry.

    DefaultMap::iter

    fn[K, V] DefaultMap::iter(self : DefaultMap[K, V]) -> Iter[(K, V)]

    The entries in insertion order.

    DefaultMap::keys

    fn[K, V] DefaultMap::keys(self : DefaultMap[K, V]) -> Iter[K]

    The keys in insertion order.

    DefaultMap::length

    fn[K, V] DefaultMap::length(self : DefaultMap[K, V]) -> Int

    How many entries the map holds.

    DefaultMap::new

    fn[K, V] DefaultMap::new(factory~ : (K) -> V, capacity? : Int, hash_seed? : Int) -> DefaultMap[K, V]

    A map that answers a missing key with factory(key). The factory runs only when get_or_init asks, so a lookup through get still reports the absence.

    DefaultMap::not_equal

    fn[K : Eq, V : Eq] DefaultMap::not_equal(x : DefaultMap[K, V], y : DefaultMap[K, V]) -> Bool

    DefaultMap::output

    fn[K : Show, V : Show] DefaultMap::output(self : DefaultMap[K, V], logger : &Logger) -> Unit

    DefaultMap::remove

    fn[K : Hash + Eq, V] DefaultMap::remove(self : DefaultMap[K, V], key : K) -> V?

    Removes key and returns the value it held.

    DefaultMap::set

    fn[K : Hash + Eq, V] DefaultMap::set(self : DefaultMap[K, V], key : K, value : V) -> V?

    Stores value under key and returns what was there.

    DefaultMap::to_string

    fn[K : Show, V : Show] DefaultMap::to_string(self : DefaultMap[K, V]) -> String

    DefaultMap::values

    fn[K, V] DefaultMap::values(self : DefaultMap[K, V]) -> Iter[V]

    The values in insertion order.

    FlatMap

    pub struct FlatMap[K, V] {
    keys : Array[K]
    values : Array[V]
    }

    A map held as a sorted array of keys with a parallel array of values: a lookup is a binary search over contiguous memory, which is the shape to reach for when a table is built once and read many times.

    test {
    let map : @map.FlatMap[Int32, String] = @map.FlatMap::new()
    let _ = map.set(2, "b")
    let _ = map.set(1, "a")
    @test.assert_eq(map.keys().to_array(), [1, 2])
    @test.assert_eq(map.get(2), Some("b"))
    @test.assert_eq(map.index_of(3), Err(2))
    }
    impl Eq for FlatMap[K, V]
    impl Show for FlatMap[K, V]

    FlatMap::capacity

    fn[K, V] FlatMap::capacity(self : FlatMap[K, V]) -> Int

    How many entries the run has room for before it grows.

    FlatMap::clear

    fn[K, V] FlatMap::clear(self : FlatMap[K, V]) -> Unit

    Removes every entry, keeping the room the run has.

    FlatMap::contains

    fn[K : Compare + Eq, V] FlatMap::contains(self : FlatMap[K, V], key : K) -> Bool

    Whether key has an entry.

    FlatMap::copy

    fn[K, V] FlatMap::copy(self : FlatMap[K, V]) -> FlatMap[K, V]

    A copy that owns its arrays: a change to either map is invisible to the other.

    FlatMap::equal

    fn[K : Eq, V : Eq] FlatMap::equal(self : FlatMap[K, V], other : FlatMap[K, V]) -> Bool

    FlatMap::first

    fn[K, V] FlatMap::first(self : FlatMap[K, V]) -> (K, V)?

    The entry with the smallest key, or None when the map is empty.

    FlatMap::from_array

    fn[K : Compare + Eq, V] FlatMap::from_array(entries : ArrayView[(K, V)]) -> FlatMap[K, V]

    Sorts the pairs by key; when a key repeats, the last pair in the array wins.

    FlatMap::get

    fn[K : Compare + Eq, V] FlatMap::get(self : FlatMap[K, V], key : K) -> V?

    The value under key, or None; the lookup is a binary search over the sorted keys.

    FlatMap::get_index

    fn[K, V] FlatMap::get_index(self : FlatMap[K, V], index : Int) -> (K, V)?

    The entry at position index in key order, or None when the position is past the last one.

    FlatMap::index_of

    fn[K : Compare + Eq, V] FlatMap::index_of(self : FlatMap[K, V], key : K) -> Result[Int, Int]

    Where key is, or where it would be inserted.

    FlatMap::is_empty

    fn[K, V] FlatMap::is_empty(self : FlatMap[K, V]) -> Bool

    Whether the map holds no entry.

    FlatMap::iter

    fn[K, V] FlatMap::iter(self : FlatMap[K, V]) -> Iter[(K, V)]

    The entries in key order.

    FlatMap::keys

    fn[K, V] FlatMap::keys(self : FlatMap[K, V]) -> Iter[K]

    The keys in order.

    FlatMap::last

    fn[K, V] FlatMap::last(self : FlatMap[K, V]) -> (K, V)?

    The entry with the largest key, or None when the map is empty.

    FlatMap::length

    fn[K, V] FlatMap::length(self : FlatMap[K, V]) -> Int

    How many entries the map holds.

    FlatMap::new

    fn[K, V] FlatMap::new(capacity? : Int) -> FlatMap[K, V]

    An empty map whose entries live in one sorted run, with room for capacity of them.

    FlatMap::not_equal

    fn[K : Eq, V : Eq] FlatMap::not_equal(x : FlatMap[K, V], y : FlatMap[K, V]) -> Bool

    FlatMap::output

    fn[K : Show, V : Show] FlatMap::output(self : FlatMap[K, V], logger : &Logger) -> Unit

    FlatMap::pop_first

    fn[K, V] FlatMap::pop_first(self : FlatMap[K, V]) -> (K, V)?

    Removes and returns the entry with the smallest key.

    FlatMap::pop_last

    fn[K, V] FlatMap::pop_last(self : FlatMap[K, V]) -> (K, V)?

    Removes and returns the entry with the largest key.

    FlatMap::range

    fn[K : Compare + Eq, V] FlatMap::range(self : FlatMap[K, V], start~ : K, end~ : K) -> Iter[(K, V)]

    The pairs whose keys fall between start and end, both included.

    FlatMap::remove

    fn[K : Compare + Eq, V] FlatMap::remove(self : FlatMap[K, V], key : K) -> V?

    Removes key and returns the value it held, closing the gap in the run.

    FlatMap::reserve_capacity

    fn[K, V] FlatMap::reserve_capacity(self : FlatMap[K, V], capacity~ : Int) -> Unit

    Makes room for capacity entries in one allocation, so the inserts that follow do not grow the run again.

    FlatMap::set

    fn[K : Compare + Eq, V] FlatMap::set(self : FlatMap[K, V], key : K, value : V) -> V?

    Stores value under key, inserting the key in order, and returns the value it replaced.

    FlatMap::shrink_to_fit

    fn[K, V] FlatMap::shrink_to_fit(self : FlatMap[K, V]) -> Unit

    Releases the room past the last entry.

    FlatMap::to_string

    fn[K : Show, V : Show] FlatMap::to_string(self : FlatMap[K, V]) -> String

    FlatMap::values

    fn[K, V] FlatMap::values(self : FlatMap[K, V]) -> Iter[V]

    The values in key order.

    FlatMultiMap

    pub struct FlatMultiMap[K, V] {
    entries : Array[(K, V)]
    }

    A multimap held as a sorted array of pairs: keys in order, and the values of one key in order among themselves. Repeats are kept, so this is the flat counterpart of SortedMultiMap.

    test {
    let map : @map.FlatMultiMap[Int32, String] = @map.FlatMultiMap::new()
    map.insert(2, "b")
    map.insert(1, "a")
    map.insert(1, "c")
    @test.assert_eq(map.get(1), ["a", "c"])
    @test.assert_eq(map.length(), 3)
    @test.assert_eq(map.key_count(), 2)
    }
    impl Eq for FlatMultiMap[K, V]
    impl Show for FlatMultiMap[K, V]

    FlatMultiMap::clear

    fn[K, V] FlatMultiMap::clear(self : FlatMultiMap[K, V]) -> Unit

    Removes every entry, keeping the room the run has.

    FlatMultiMap::contains

    fn[K : Compare + Eq, V] FlatMultiMap::contains(self : FlatMultiMap[K, V], key : K) -> Bool

    Whether key has at least one value.

    FlatMultiMap::copy

    fn[K, V] FlatMultiMap::copy(self : FlatMultiMap[K, V]) -> FlatMultiMap[K, V]

    A copy that owns its array: a change to either multimap is invisible to the other.

    FlatMultiMap::count

    fn[K : Compare + Eq, V] FlatMultiMap::count(self : FlatMultiMap[K, V], key : K) -> Int

    How many values are stored under key.

    FlatMultiMap::equal

    fn[K : Eq, V : Eq] FlatMultiMap::equal(self : FlatMultiMap[K, V], other : FlatMultiMap[K, V]) -> Bool

    FlatMultiMap::first

    fn[K, V] FlatMultiMap::first(self : FlatMultiMap[K, V]) -> (K, V)?

    The smallest entry, or None when the map is empty.

    FlatMultiMap::get

    fn[K : Compare + Eq, V] FlatMultiMap::get(self : FlatMultiMap[K, V], key : K) -> Array[V]

    The values under key, ascending.

    FlatMultiMap::insert

    fn[K : Compare + Eq, V : Compare + Eq] FlatMultiMap::insert(self : FlatMultiMap[K, V], key : K, value : V) -> Unit

    Adds value under key in sorted position; a pair that is already there is not added twice.

    FlatMultiMap::is_empty

    fn[K, V] FlatMultiMap::is_empty(self : FlatMultiMap[K, V]) -> Bool

    Whether no value is stored under any key.

    FlatMultiMap::iter

    fn[K, V] FlatMultiMap::iter(self : FlatMultiMap[K, V]) -> Iter[(K, V)]

    Every entry in key order, and within one key in value order.

    FlatMultiMap::key_count

    fn[K : Compare + Eq, V] FlatMultiMap::key_count(self : FlatMultiMap[K, V]) -> Int

    The number of distinct keys.

    FlatMultiMap::last

    fn[K, V] FlatMultiMap::last(self : FlatMultiMap[K, V]) -> (K, V)?

    The largest entry, or None when the map is empty.

    FlatMultiMap::length

    fn[K, V] FlatMultiMap::length(self : FlatMultiMap[K, V]) -> Int

    How many entries, counting one per value, the map holds.

    FlatMultiMap::new

    fn[K, V] FlatMultiMap::new(capacity? : Int) -> FlatMultiMap[K, V]

    An empty multimap whose entries live in one run sorted by key and then by value, with room for capacity of them.

    FlatMultiMap::not_equal

    fn[K : Eq, V : Eq] FlatMultiMap::not_equal(x : FlatMultiMap[K, V], y : FlatMultiMap[K, V]) -> Bool

    FlatMultiMap::output

    fn[K : Show, V : Show] FlatMultiMap::output(self : FlatMultiMap[K, V], logger : &Logger) -> Unit

    FlatMultiMap::pop_first

    fn[K, V] FlatMultiMap::pop_first(self : FlatMultiMap[K, V]) -> (K, V)?

    Removes and returns the smallest entry.

    FlatMultiMap::pop_last

    fn[K, V] FlatMultiMap::pop_last(self : FlatMultiMap[K, V]) -> (K, V)?

    Removes and returns the largest entry.

    FlatMultiMap::range

    fn[K : Compare + Eq, V] FlatMultiMap::range(self : FlatMultiMap[K, V], start~ : K, end~ : K) -> Iter[(K, V)]

    Every entry whose key is from start up to end, in order.

    FlatMultiMap::remove

    fn[K : Compare + Eq, V] FlatMultiMap::remove(self : FlatMultiMap[K, V], key : K) -> Array[V]

    Drops every value of key and returns them.

    FlatMultiMap::remove_entry

    fn[K : Compare + Eq, V : Compare + Eq] FlatMultiMap::remove_entry(self : FlatMultiMap[K, V], key : K, value : V) -> Bool

    Drops one pair equal to (key, value).

    FlatMultiMap::to_array

    fn[K, V] FlatMultiMap::to_array(self : FlatMultiMap[K, V]) -> Array[(K, V)]

    Every entry in key order, as a new array.

    FlatMultiMap::to_string

    fn[K : Show, V : Show] FlatMultiMap::to_string(self : FlatMultiMap[K, V]) -> String

    FlatSet

    pub struct FlatSet[K] {
    keys : Array[K]
    }

    A set held as a sorted array of elements, the companion of FlatMap.

    test {
    let set : @map.FlatSet[Int32] = @map.FlatSet::new()
    @test.assert_eq(set.insert(3), true)
    @test.assert_eq(set.insert(3), false)
    @test.assert_eq(set.get_index(0), Some(3))
    }
    impl Eq for FlatSet[K]
    impl Show for FlatSet[K]

    FlatSet::capacity

    fn[K] FlatSet::capacity(self : FlatSet[K]) -> Int

    How many values the run has room for before it grows.

    FlatSet::clear

    fn[K] FlatSet::clear(self : FlatSet[K]) -> Unit

    Removes every value, keeping the room the run has.

    FlatSet::contains

    fn[K : Compare + Eq] FlatSet::contains(self : FlatSet[K], key : K) -> Bool

    Whether value is in the set; the lookup is a binary search over the sorted run.

    FlatSet::copy

    fn[K] FlatSet::copy(self : FlatSet[K]) -> FlatSet[K]

    A copy that owns its array: a change to either set is invisible to the other.

    FlatSet::equal

    fn[K : Eq] FlatSet::equal(self : FlatSet[K], other : FlatSet[K]) -> Bool

    FlatSet::first

    fn[K] FlatSet::first(self : FlatSet[K]) -> K?

    The smallest value, or None when the set is empty.

    FlatSet::from_array

    fn[K : Compare + Eq] FlatSet::from_array(values : ArrayView[K]) -> FlatSet[K]

    A set holding the values written out, in order and without repeats.

    FlatSet::get_index

    fn[K] FlatSet::get_index(self : FlatSet[K], index : Int) -> K?

    The value at position index in order, or None when the position is past the last one.

    FlatSet::index_of

    fn[K : Compare + Eq] FlatSet::index_of(self : FlatSet[K], key : K) -> Result[Int, Int]

    Where key is, or where it would be inserted.

    FlatSet::insert

    fn[K : Compare + Eq] FlatSet::insert(self : FlatSet[K], key : K) -> Bool

    Adds the element and reports whether it was new.

    FlatSet::is_empty

    fn[K] FlatSet::is_empty(self : FlatSet[K]) -> Bool

    Whether the set holds no value.

    FlatSet::iter

    fn[K] FlatSet::iter(self : FlatSet[K]) -> Iter[K]

    The values in order.

    FlatSet::last

    fn[K] FlatSet::last(self : FlatSet[K]) -> K?

    The largest value, or None when the set is empty.

    FlatSet::length

    fn[K] FlatSet::length(self : FlatSet[K]) -> Int

    How many values the set holds.

    FlatSet::new

    fn[K] FlatSet::new(capacity? : Int) -> FlatSet[K]

    An empty set whose values live in one sorted run, with room for capacity of them.

    FlatSet::not_equal

    fn[K : Eq] FlatSet::not_equal(x : FlatSet[K], y : FlatSet[K]) -> Bool

    FlatSet::output

    fn[K : Show] FlatSet::output(self : FlatSet[K], logger : &Logger) -> Unit

    FlatSet::pop_first

    fn[K] FlatSet::pop_first(self : FlatSet[K]) -> K?

    Removes and returns the smallest value.

    FlatSet::pop_last

    fn[K] FlatSet::pop_last(self : FlatSet[K]) -> K?

    Removes and returns the largest value.

    FlatSet::range

    fn[K : Compare + Eq] FlatSet::range(self : FlatSet[K], start~ : K, end~ : K) -> Iter[K]

    The values from start up to end, in order.

    FlatSet::remove

    fn[K : Compare + Eq] FlatSet::remove(self : FlatSet[K], key : K) -> Bool

    Removes value, closing the gap in the run, and reports whether it was there.

    FlatSet::reserve_capacity

    fn[K] FlatSet::reserve_capacity(self : FlatSet[K], capacity~ : Int) -> Unit

    Makes room for capacity values in one allocation.

    FlatSet::shrink_to_fit

    fn[K] FlatSet::shrink_to_fit(self : FlatSet[K]) -> Unit

    Releases the room past the last value.

    FlatSet::to_array

    fn[K] FlatSet::to_array(self : FlatSet[K]) -> Array[K]

    The values in order, as a new array.

    FlatSet::to_string

    fn[K : Show] FlatSet::to_string(self : FlatSet[K]) -> String

    IndexMap

    pub struct IndexMap[K, V] {
    entries : Array[(K, V)]
    hashes : Array[Int]
    slots : Array[Int]
    slot_of : Array[Int]
    live : Int
    graves : Int
    seed : Int
    }

    An associative container that keeps insertion order and gives every entry a position: get_index reads by position, get_index_of reads the position of a key, and the entries can be reordered without touching the table's contents. swap_remove is the default removal because it is O(1); a caller that needs the remaining positions to stay contiguous uses shift_remove.

    test {
    let map : @map.IndexMap[String, Int32] = @map.IndexMap::new()
    let _ = map.set("a", 1)
    let _ = map.set("b", 2)
    @test.assert_eq(map.get_index_of("b"), Some(1))
    @test.assert_eq(map.get_index(0), Some(("a", 1)))
    let _ = map.swap_remove("a")
    @test.assert_eq(map.get_index(0), Some(("b", 2)))
    }
    impl Eq for IndexMap[K, V]
    impl Hash for IndexMap[K, V]
    impl Show for IndexMap[K, V]

    IndexMap::capacity

    fn[K, V] IndexMap::capacity(self : IndexMap[K, V]) -> Int

    The number of slots the table has, which is what reserve_capacity raises.

    IndexMap::clear

    fn[K, V] IndexMap::clear(self : IndexMap[K, V]) -> Unit

    Removes every entry, keeping the seed the map was made with.

    IndexMap::contains

    fn[K : Hash + Eq, V] IndexMap::contains(self : IndexMap[K, V], key : K) -> Bool

    Whether key has an entry.

    IndexMap::copy

    fn[K, V] IndexMap::copy(self : IndexMap[K, V]) -> IndexMap[K, V]

    A copy that owns its arrays: a change to either map is invisible to the other.

    IndexMap::equal

    fn[K : Eq, V : Eq] IndexMap::equal(self : IndexMap[K, V], other : IndexMap[K, V]) -> Bool

    IndexMap::from_array

    fn[K : Hash + Eq, V] IndexMap::from_array(entries : ArrayView[(K, V)], hash_seed? : Int) -> IndexMap[K, V]

    A map holding the entries written out, in the order given. A key that appears twice keeps its first position and takes the last value.

    IndexMap::from_iter

    fn[K : Hash + Eq, V] IndexMap::from_iter(entries : Iter[(K, V)], hash_seed? : Int) -> IndexMap[K, V]

    A map holding the entries the iterator yields, in the order they arrive.

    IndexMap::get

    fn[K : Hash + Eq, V] IndexMap::get(self : IndexMap[K, V], key : K) -> V?

    The value under key, or None when no entry has it.

    IndexMap::get_full

    fn[K : Hash + Eq, V] IndexMap::get_full(self : IndexMap[K, V], key : K) -> (Int, K, V)?

    The position, key and value of key, read in one lookup.

    IndexMap::get_index

    fn[K, V] IndexMap::get_index(self : IndexMap[K, V], index : Int) -> (K, V)?

    The entry at position index, or None when the position is past the last one.

    IndexMap::get_index_of

    fn[K : Hash + Eq, V] IndexMap::get_index_of(self : IndexMap[K, V], key : K) -> Int?

    The position key sits at, or None when it has no entry.

    IndexMap::get_key_value

    fn[K : Hash + Eq, V] IndexMap::get_key_value(self : IndexMap[K, V], key : K) -> (K, V)?

    The key and the value of an entry, which unlike get hands back the key the map actually holds.

    IndexMap::hash

    fn[K : Hash, V : Hash] IndexMap::hash(self : IndexMap[K, V]) -> Int

    IndexMap::hash_combine

    fn[K : Hash, V : Hash] IndexMap::hash_combine(self : IndexMap[K, V], hasher : Hasher) -> Unit

    IndexMap::insert_full

    fn[K : Hash + Eq, V] IndexMap::insert_full(self : IndexMap[K, V], key : K, value : V) -> (Int, V?)

    The entry index of key after storing value there, and the value that was there before. The position of an existing entry does not change.

    IndexMap::is_empty

    fn[K, V] IndexMap::is_empty(self : IndexMap[K, V]) -> Bool

    Whether the map holds no entry.

    IndexMap::iter

    fn[K, V] IndexMap::iter(self : IndexMap[K, V]) -> Iter[(K, V)]

    The entries in position order.

    IndexMap::iter2

    fn[K, V] IndexMap::iter2(self : IndexMap[K, V]) -> Iter2[K, V]

    The keys and the values in position order, as a two-part iterator.

    IndexMap::keys

    fn[K, V] IndexMap::keys(self : IndexMap[K, V]) -> Iter[K]

    The keys in position order.

    IndexMap::length

    fn[K, V] IndexMap::length(self : IndexMap[K, V]) -> Int

    How many entries the map holds.

    IndexMap::move_index

    fn[K, V] IndexMap::move_index(self : IndexMap[K, V], from : Int, to : Int) -> Unit

    Moves the entry at from to to, shifting everything between them.

    IndexMap::new

    fn[K, V] IndexMap::new(capacity? : Int, hash_seed? : Int) -> IndexMap[K, V]

    A table with room for capacity entries, laid out from hash_seed. A fixed seed makes the layout, and with it nothing visible, reproducible; the order of the entries does not depend on it.

    IndexMap::not_equal

    fn[K : Eq, V : Eq] IndexMap::not_equal(x : IndexMap[K, V], y : IndexMap[K, V]) -> Bool

    IndexMap::output

    fn[K : Show, V : Show] IndexMap::output(self : IndexMap[K, V], logger : &Logger) -> Unit

    IndexMap::range

    fn[K, V] IndexMap::range(self : IndexMap[K, V], start~ : Int, len~ : Int) -> Iter[(K, V)]

    The entries from start for len positions, clamped to the container.

    IndexMap::remove

    fn[K : Hash + Eq, V] IndexMap::remove(self : IndexMap[K, V], key : K) -> V?

    Removes key the way swap_remove does and hands back the value it held.

    IndexMap::reserve_capacity

    fn[K, V] IndexMap::reserve_capacity(self : IndexMap[K, V], capacity~ : Int) -> Unit

    Lays the table out again with room for capacity entries, so the inserts that follow do not rehash.

    IndexMap::retain

    fn[K, V] IndexMap::retain(self : IndexMap[K, V], f : (K, V) -> Bool) -> Unit

    Keeps the entries the predicate accepts, in their order, and renumbers the positions when any were dropped.

    IndexMap::set

    fn[K : Hash + Eq, V] IndexMap::set(self : IndexMap[K, V], key : K, value : V) -> V?

    Stores value under key and returns the value it replaced.

    IndexMap::set_default

    fn[K : Hash + Eq, V] IndexMap::set_default(self : IndexMap[K, V], key : K, value : V) -> V

    Stores value under key only when the key is new, which is how a caller keeps the first value written.

    IndexMap::shift_remove

    fn[K : Hash + Eq, V] IndexMap::shift_remove(self : IndexMap[K, V], key : K) -> V?

    Removes key by shifting every later entry down one position, so the positions that remain are the ones they were; O(n).

    IndexMap::shift_remove_index

    fn[K, V] IndexMap::shift_remove_index(self : IndexMap[K, V], index : Int) -> (K, V)?

    Removes the entry at index and closes the gap, so every entry after it moves down one position.

    IndexMap::shrink_to_fit

    fn[K, V] IndexMap::shrink_to_fit(self : IndexMap[K, V]) -> Unit

    Lays the table out again at the smallest size that holds the entries, dropping the slots removals left behind.

    IndexMap::sort_by

    fn[K, V] IndexMap::sort_by(self : IndexMap[K, V], cmp : ((K, V), (K, V)) -> Int) -> Unit

    Reorders the entries by cmp, which sees the whole entry rather than only its key, and renumbers the positions.

    IndexMap::sort_by_key

    fn[K, V, R : Compare + Eq] IndexMap::sort_by_key(self : IndexMap[K, V], project~ : (K) -> R) -> Unit

    Reorders the entries by a projection of the key and renumbers the positions.

    IndexMap::sort_keys

    fn[K : Compare + Eq, V] IndexMap::sort_keys(self : IndexMap[K, V]) -> Unit

    Sorts the entries by key and renumbers the positions.

    IndexMap::split_off

    fn[K : Hash + Eq, V] IndexMap::split_off(self : IndexMap[K, V], at : Int) -> IndexMap[K, V]

    The entries from at on, as a new map; this map keeps the ones before it.

    IndexMap::swap_indices

    fn[K, V] IndexMap::swap_indices(self : IndexMap[K, V], a : Int, b : Int) -> Unit

    Exchanges the entries at two positions. Both keys keep their slots in the table, so this costs a swap and not a rehash; an index that is out of range leaves the map as it was.

    IndexMap::swap_remove

    fn[K : Hash + Eq, V] IndexMap::swap_remove(self : IndexMap[K, V], key : K) -> V?

    Removes key by moving the last entry into its position, so the entries stay dense and the cost is O(1). The positions of the entries after the hole therefore change.

    IndexMap::swap_remove_index

    fn[K, V] IndexMap::swap_remove_index(self : IndexMap[K, V], index : Int) -> (K, V)?

    Removes the entry at index by moving the last entry into its place, and returns it. The entry that moved keeps its key and takes the removed position.

    IndexMap::to_array

    fn[K, V] IndexMap::to_array(self : IndexMap[K, V]) -> Array[(K, V)]

    The entries in position order, as a new array.

    IndexMap::to_string

    fn[K : Show, V : Show] IndexMap::to_string(self : IndexMap[K, V]) -> String

    IndexMap::truncate

    fn[K, V] IndexMap::truncate(self : IndexMap[K, V], length : Int) -> Unit

    Keeps the first length entries and drops the rest; a length past the end leaves the map alone.

    IndexMap::update

    fn[K : Hash + Eq, V] IndexMap::update(self : IndexMap[K, V], key : K, f : (V) -> V) -> Bool

    Replaces the value of an entry that is already there, and reports whether there was one.

    IndexMap::values

    fn[K, V] IndexMap::values(self : IndexMap[K, V]) -> Iter[V]

    The values in position order.

    IndexSet

    pub struct IndexSet[K] {
    map : IndexMap[K, Unit]
    }

    A set that keeps insertion order and gives every element a position, the companion of IndexMap the way HashSet is the companion of HashMap.

    test {
    let set : @map.IndexSet[Int32] = @map.IndexSet::new()
    @test.assert_eq(set.insert(7), (0, true))
    @test.assert_eq(set.insert(7), (0, false))
    @test.assert_eq(set.get_index(0), Some(7))
    }
    impl Eq for IndexSet[K]
    impl Hash for IndexSet[K]
    impl Show for IndexSet[K]

    IndexSet::capacity

    fn[K] IndexSet::capacity(self : IndexSet[K]) -> Int

    How many values the table behind the set has room for before it is laid out again.

    IndexSet::clear

    fn[K] IndexSet::clear(self : IndexSet[K]) -> Unit

    Removes every value, keeping the seed the set was made with.

    IndexSet::contains

    fn[K : Hash + Eq] IndexSet::contains(self : IndexSet[K], value : K) -> Bool

    Whether value is in the set.

    IndexSet::copy

    fn[K] IndexSet::copy(self : IndexSet[K]) -> IndexSet[K]

    A copy that owns its arrays: a change to either set is invisible to the other.

    IndexSet::difference

    fn[K : Hash + Eq] IndexSet::difference(self : IndexSet[K], other : IndexSet[K]) -> IndexSet[K]

    The elements of this set that are not in other, in this set's order.

    IndexSet::equal

    fn[K : Eq] IndexSet::equal(self : IndexSet[K], other : IndexSet[K]) -> Bool

    IndexSet::first

    fn[K] IndexSet::first(self : IndexSet[K]) -> K?

    The value at position 0, or None when the set is empty.

    IndexSet::from_array

    fn[K : Hash + Eq] IndexSet::from_array(values : ArrayView[K], hash_seed? : Int) -> IndexSet[K]

    A set holding the values written out, in the order given.

    IndexSet::from_iter

    fn[K : Hash + Eq] IndexSet::from_iter(values : Iter[K], hash_seed? : Int) -> IndexSet[K]

    A set holding the values the iterator yields, in the order they arrive.

    IndexSet::get_index

    fn[K] IndexSet::get_index(self : IndexSet[K], index : Int) -> K?

    The value at position index, or None when the position is past the last one.

    IndexSet::get_index_of

    fn[K : Hash + Eq] IndexSet::get_index_of(self : IndexSet[K], value : K) -> Int?

    The position value sits at, or None when it is not in the set.

    IndexSet::hash

    fn[K : Hash] IndexSet::hash(self : IndexSet[K]) -> Int

    IndexSet::hash_combine

    fn[K : Hash] IndexSet::hash_combine(self : IndexSet[K], hasher : Hasher) -> Unit

    IndexSet::insert

    fn[K : Hash + Eq] IndexSet::insert(self : IndexSet[K], value : K) -> (Int, Bool)

    The position of the element and whether it was new.

    IndexSet::intersection

    fn[K : Hash + Eq] IndexSet::intersection(self : IndexSet[K], other : IndexSet[K]) -> IndexSet[K]

    A new set holding the values in both, in the order this one holds them.

    IndexSet::is_disjoint

    fn[K : Hash + Eq] IndexSet::is_disjoint(self : IndexSet[K], other : IndexSet[K]) -> Bool

    Whether the two sets share no value.

    IndexSet::is_empty

    fn[K] IndexSet::is_empty(self : IndexSet[K]) -> Bool

    Whether the set holds no value.

    IndexSet::is_subset

    fn[K : Hash + Eq] IndexSet::is_subset(self : IndexSet[K], other : IndexSet[K]) -> Bool

    Whether every value of this set is in other.

    IndexSet::is_superset

    fn[K : Hash + Eq] IndexSet::is_superset(self : IndexSet[K], other : IndexSet[K]) -> Bool

    Whether every value of other is in this set.

    IndexSet::iter

    fn[K] IndexSet::iter(self : IndexSet[K]) -> Iter[K]

    The values in position order.

    IndexSet::last

    fn[K] IndexSet::last(self : IndexSet[K]) -> K?

    The value at the last position, or None when the set is empty.

    IndexSet::length

    fn[K] IndexSet::length(self : IndexSet[K]) -> Int

    How many values the set holds.

    IndexSet::move_index

    fn[K] IndexSet::move_index(self : IndexSet[K], from : Int, to : Int) -> Unit

    Moves the value at one position to another and closes the gap, so no position is skipped.

    IndexSet::new

    fn[K] IndexSet::new(capacity? : Int, hash_seed? : Int) -> IndexSet[K]

    A set with room for capacity values, laid out from hash_seed.

    IndexSet::not_equal

    fn[K : Eq] IndexSet::not_equal(x : IndexSet[K], y : IndexSet[K]) -> Bool

    IndexSet::output

    fn[K : Show] IndexSet::output(self : IndexSet[K], logger : &Logger) -> Unit

    IndexSet::range

    fn[K] IndexSet::range(self : IndexSet[K], start~ : Int, len~ : Int) -> Iter[K]

    The elements from start for len positions.

    IndexSet::remove

    fn[K : Hash + Eq] IndexSet::remove(self : IndexSet[K], value : K) -> Bool

    Removes value the way swap_remove does and reports whether it was there.

    IndexSet::retain

    fn[K] IndexSet::retain(self : IndexSet[K], f : (K) -> Bool) -> Unit

    Keeps the values f accepts and removes the rest, holding their order.

    IndexSet::shift_remove

    fn[K : Hash + Eq] IndexSet::shift_remove(self : IndexSet[K], value : K) -> Bool

    Removes value by shifting every later value down one position, so the positions that remain are the ones they were; O(n).

    IndexSet::sort_by

    fn[K] IndexSet::sort_by(self : IndexSet[K], cmp : (K, K) -> Int) -> Unit

    Reorders the values by cmp.

    IndexSet::sort_keys

    fn[K : Compare + Eq] IndexSet::sort_keys(self : IndexSet[K]) -> Unit

    Reorders the values ascending by their own order.

    IndexSet::swap_indices

    fn[K] IndexSet::swap_indices(self : IndexSet[K], a : Int, b : Int) -> Unit

    Exchanges the values at two positions, leaving the set's contents alone.

    IndexSet::swap_remove

    fn[K : Hash + Eq] IndexSet::swap_remove(self : IndexSet[K], value : K) -> Bool

    Removes value by moving the last value into its position, so the values stay dense and the cost is O(1).

    IndexSet::symmetric_difference

    fn[K : Hash + Eq] IndexSet::symmetric_difference(self : IndexSet[K], other : IndexSet[K]) -> IndexSet[K]

    A new set holding the values in exactly one of the two.

    IndexSet::to_array

    fn[K] IndexSet::to_array(self : IndexSet[K]) -> Array[K]

    The values in position order, as a new array.

    IndexSet::to_string

    fn[K : Show] IndexSet::to_string(self : IndexSet[K]) -> String

    IndexSet::union

    fn[K : Hash + Eq] IndexSet::union(self : IndexSet[K], other : IndexSet[K]) -> IndexSet[K]

    The elements of this set followed by the ones only other has.

    MultiMap

    pub struct MultiMap[K, V] {
    map : IndexMap[K, Array[V]]
    total : Int
    }

    A map from a key to a list of values: one entry per key, and the values of a key keep the order they were inserted in.

    test {
    let map : @map.MultiMap[String, Int32] = @map.MultiMap::new()
    map.insert("a", 1)
    map.insert("a", 2)
    @test.assert_eq(map.get("a"), [1, 2])
    @test.assert_eq(map.length(), 2)
    @test.assert_eq(map.key_count(), 1)
    }
    impl Eq for MultiMap[K, V]
    impl Show for MultiMap[K, V]

    MultiMap::clear

    fn[K, V] MultiMap::clear(self : MultiMap[K, V]) -> Unit

    Removes every key and every value.

    MultiMap::contains

    fn[K : Hash + Eq, V] MultiMap::contains(self : MultiMap[K, V], key : K) -> Bool

    Whether key has at least one value.

    MultiMap::contains_entry

    fn[K : Hash + Eq, V : Eq] MultiMap::contains_entry(self : MultiMap[K, V], key : K, value : V) -> Bool

    Whether value is one of the values under key.

    MultiMap::copy

    fn[K : Hash + Eq, V] MultiMap::copy(self : MultiMap[K, V]) -> MultiMap[K, V]

    A copy that owns its arrays: a change to either multimap is invisible to the other.

    MultiMap::equal

    fn[K : Eq, V : Eq] MultiMap::equal(self : MultiMap[K, V], other : MultiMap[K, V]) -> Bool

    MultiMap::get

    fn[K : Hash + Eq, V] MultiMap::get(self : MultiMap[K, V], key : K) -> Array[V]

    The values of key, in insertion order. The array is a copy, so a caller cannot write into the map through it.

    MultiMap::insert

    fn[K : Hash + Eq, V] MultiMap::insert(self : MultiMap[K, V], key : K, value : V) -> Unit

    Adds value under key, keeping the values of a key in the order they were added.

    MultiMap::is_empty

    fn[K, V] MultiMap::is_empty(self : MultiMap[K, V]) -> Bool

    Whether no value is stored under any key.

    MultiMap::iter

    fn[K, V] MultiMap::iter(self : MultiMap[K, V]) -> Iter[(K, V)]

    Every pair, key by key, the values of a key in insertion order.

    MultiMap::iter2

    fn[K, V] MultiMap::iter2(self : MultiMap[K, V]) -> Iter2[K, V]

    Every value paired with its key, in key order and then in the order the values were added.

    MultiMap::iter_values

    fn[K : Hash + Eq, V] MultiMap::iter_values(self : MultiMap[K, V], key : K) -> Iter[V]

    The values under key, in the order they were added; a key that is absent yields nothing.

    MultiMap::key_count

    fn[K, V] MultiMap::key_count(self : MultiMap[K, V]) -> Int

    The number of distinct keys.

    MultiMap::keys

    fn[K, V] MultiMap::keys(self : MultiMap[K, V]) -> Iter[K]

    The keys in the order they were first added.

    MultiMap::length

    fn[K, V] MultiMap::length(self : MultiMap[K, V]) -> Int

    The number of values held, counting repeats.

    MultiMap::new

    fn[K, V] MultiMap::new(capacity? : Int, hash_seed? : Int) -> MultiMap[K, V]

    A multimap with room for capacity values, its key table laid out from hash_seed.

    MultiMap::not_equal

    fn[K : Eq, V : Eq] MultiMap::not_equal(x : MultiMap[K, V], y : MultiMap[K, V]) -> Bool

    MultiMap::output

    fn[K : Show, V : Show] MultiMap::output(self : MultiMap[K, V], logger : &Logger) -> Unit

    MultiMap::remove

    fn[K : Hash + Eq, V] MultiMap::remove(self : MultiMap[K, V], key : K) -> Array[V]

    Drops every value of key and returns them.

    MultiMap::remove_entry

    fn[K : Hash + Eq, V : Eq] MultiMap::remove_entry(self : MultiMap[K, V], key : K, value : V) -> Bool

    Drops one occurrence of value under key.

    MultiMap::to_string

    fn[K : Show, V : Show] MultiMap::to_string(self : MultiMap[K, V]) -> String

    Overlap

    pub(all) enum Overlap {
    Overwrite
    Refuse
    KeepFirst
    } derive(Eq,
    Debug
    )

    What an insert does when the new range meets one that is already there.
    impl Show for Overlap

    Overlap::equal

    fn Overlap::equal(Overlap, Overlap) -> Bool

    Overlap::not_equal

    fn Overlap::not_equal(x : Overlap, y : Overlap) -> Bool

    Overlap::output

    fn Overlap::output(self : Overlap, logger : &Logger) -> Unit

    Overlap::to_repr

    Overlap::to_string

    fn Overlap::to_string(self : Overlap) -> String

    RadixTree

    pub struct RadixTree[T] {
    labels : Array[Array[Char]]
    children : Array[Map[Char, Int]]
    values : Array[T?]
    entries : Int
    }

    A trie with its chains of single-child nodes collapsed into one edge per label: a lookup compares whole labels instead of single characters, which is what keeps a tree over long shared prefixes shallow. The surface is the Trie surface, plus the queries that only make sense over a compressed tree: the keys that are prefixes of a given key, a count of the keys under a prefix, and a scan of that subtree.

    test {
    let tree : @map.RadixTree[Int32] = @map.RadixTree::new()
    @test.assert_eq(tree.insert("car", 1), None)
    @test.assert_eq(tree.insert("cart", 2), None)
    @test.assert_eq(tree.insert("cat", 3), None)
    @test.assert_eq(tree.get("cart"), Some(2))
    @test.assert_eq(tree.get_ancestor_keys("cartoon"), ["car", "cart"])
    @test.assert_eq(tree.prefix_count("ca"), 3)
    }
    impl Show for RadixTree[T]

    RadixTree::clear

    fn[T] RadixTree::clear(self : RadixTree[T]) -> Unit

    Removes every key, leaving the root.

    RadixTree::contains

    fn[T] RadixTree::contains(self : RadixTree[T], key : StringView) -> Bool

    Whether key is stored.

    RadixTree::contains_prefix

    fn[T] RadixTree::contains_prefix(self : RadixTree[T], prefix : StringView) -> Bool

    Whether some stored key begins with prefix.

    RadixTree::copy

    fn[T] RadixTree::copy(self : RadixTree[T]) -> RadixTree[T]

    A copy that shares nothing with the original: a write to either is invisible to the other.

    RadixTree::get

    fn[T] RadixTree::get(self : RadixTree[T], key : StringView) -> T?

    The value stored under key, or None.

    RadixTree::get_ancestor_keys

    fn[T] RadixTree::get_ancestor_keys(self : RadixTree[T], key : StringView) -> Array[String]

    The stored keys that are prefixes of key, shortest first.

    RadixTree::insert

    fn[T] RadixTree::insert(self : RadixTree[T], key : StringView, value : T) -> T?

    Stores value under key and returns what the key held before.

    RadixTree::is_empty

    fn[T] RadixTree::is_empty(self : RadixTree[T]) -> Bool

    Whether no key is stored.

    RadixTree::iter

    fn[T] RadixTree::iter(self : RadixTree[T]) -> Iter[(String, T)]

    Every stored key and its value, in tree order.

    RadixTree::iter_prefix

    fn[T] RadixTree::iter_prefix(self : RadixTree[T], prefix : StringView) -> Iter[(String, T)]

    The keys under prefix, in character order.

    RadixTree::keys_with_prefix

    fn[T] RadixTree::keys_with_prefix(self : RadixTree[T], prefix : StringView) -> Array[String]

    Every stored key that begins with prefix, in tree order.

    RadixTree::length

    fn[T] RadixTree::length(self : RadixTree[T]) -> Int

    How many keys are stored.

    RadixTree::longest_prefix

    fn[T] RadixTree::longest_prefix(self : RadixTree[T], text : StringView) -> (String, T)?

    The longest stored key that is a prefix of text, with its value.

    RadixTree::new

    fn[T] RadixTree::new() -> RadixTree[T]

    An empty tree, holding no key.

    RadixTree::output

    fn[T : Show] RadixTree::output(self : RadixTree[T], logger : &Logger) -> Unit

    RadixTree::prefix_count

    fn[T] RadixTree::prefix_count(self : RadixTree[T], prefix : StringView) -> Int

    How many stored keys start with prefix.

    RadixTree::remove

    fn[T] RadixTree::remove(self : RadixTree[T], key : StringView) -> T?

    Drops the value under key, and the nodes the removal left empty.

    RadixTree::to_array

    fn[T] RadixTree::to_array(self : RadixTree[T]) -> Array[(String, T)]

    Every stored key and its value, in tree order, as a new array.

    RadixTree::to_string

    fn[T : Show] RadixTree::to_string(self : RadixTree[T]) -> String

    RangeMap

    pub struct RangeMap[K, V] {
    ranges : Array[(K, K, V)]
    overlap : Overlap
    }

    A value that holds over a span of keys: the ranges are kept sorted, never overlap each other, and two ranges that touch and hold the same value are kept as one. A range is half-open — it covers start and stops before end — so an insert that meets a neighbour at one endpoint does not collide with it.

    test {
    let map : @map.RangeMap[Int32, String] = @map.RangeMap::new()
    map.insert(start=0, end=10, "low")
    map.insert(start=10, end=20, "high")
    @test.assert_eq(map.get(5), Some("low"))
    @test.assert_eq(map.get(10), Some("high"))
    @test.assert_eq(map.get(20), None)
    @test.assert_eq(map.length(), 2)
    }
    impl Eq for RangeMap[K, V]
    impl Show for RangeMap[K, V]

    RangeMap::clear

    fn[K, V] RangeMap::clear(self : RangeMap[K, V]) -> Unit

    Removes every range, keeping the overlap policy.

    RangeMap::copy

    fn[K, V] RangeMap::copy(self : RangeMap[K, V]) -> RangeMap[K, V]

    A copy that owns its array: a change to either map is invisible to the other.

    RangeMap::equal

    fn[K : Eq, V : Eq] RangeMap::equal(self : RangeMap[K, V], other : RangeMap[K, V]) -> Bool

    RangeMap::gaps

    fn[K, V] RangeMap::gaps(self : RangeMap[K, V]) -> Iter[(K, K)]

    The spans no range covers, in start order.

    RangeMap::get

    fn[K : Compare + Eq, V] RangeMap::get(self : RangeMap[K, V], key : K) -> V?

    The value covering key, or None when no range does.

    RangeMap::get_range

    fn[K : Compare + Eq, V] RangeMap::get_range(self : RangeMap[K, V], key : K) -> (K, K, V)?

    The range covering key — its start, its end and its value — or None.

    RangeMap::insert

    fn[K : Compare + Eq, V : Eq] RangeMap::insert(self : RangeMap[K, V], start~ : K, end~ : K, value : V) -> Unit raise
    Refused

    Stores value over [start, end), applying the overlap policy and folding the result into its neighbours.

    RangeMap::is_empty

    fn[K, V] RangeMap::is_empty(self : RangeMap[K, V]) -> Bool

    Whether the map holds no range.

    RangeMap::length

    fn[K, V] RangeMap::length(self : RangeMap[K, V]) -> Int

    How many ranges the map holds.

    RangeMap::new

    fn[K, V] RangeMap::new(overlap? : Overlap) -> RangeMap[K, V]

    An empty range map whose policy for an overlapping insert is overlap: Overwrite cuts the existing ranges back, Refuse raises Refused::Overlap, KeepFirst drops the incoming one.

    RangeMap::not_equal

    fn[K : Eq, V : Eq] RangeMap::not_equal(x : RangeMap[K, V], y : RangeMap[K, V]) -> Bool

    RangeMap::output

    fn[K : Show, V : Show] RangeMap::output(self : RangeMap[K, V], logger : &Logger) -> Unit

    RangeMap::overlapping

    fn[K : Compare + Eq, V] RangeMap::overlapping(self : RangeMap[K, V], start~ : K, end~ : K) -> Array[(K, K, V)]

    Every range that meets [start, end), in start order.

    RangeMap::ranges

    fn[K, V] RangeMap::ranges(self : RangeMap[K, V]) -> Iter[(K, K, V)]

    The ranges, in start order.

    RangeMap::remove

    fn[K : Compare + Eq, V] RangeMap::remove(self : RangeMap[K, V], start~ : K, end~ : K) -> Unit

    Drops the part of every range that falls in [start, end), splitting a range that straddles it.

    RangeMap::to_string

    fn[K : Show, V : Show] RangeMap::to_string(self : RangeMap[K, V]) -> String

    RangeSet

    pub struct RangeSet[K] {
    ranges : Array[(K, K)]
    overlap : Overlap
    }

    A set of spans: the companion of RangeMap with no value to carry.

    test {
    let set : @map.RangeSet[Int32] = @map.RangeSet::new()
    set.insert(start=0, end=5)
    set.insert(start=5, end=9)
    @test.assert_eq(set.contains(7), true)
    @test.assert_eq(set.contains(9), false)
    @test.assert_eq(set.length(), 1)
    }
    impl Eq for RangeSet[K]
    impl Show for RangeSet[K]

    RangeSet::clear

    fn[K] RangeSet::clear(self : RangeSet[K]) -> Unit

    Removes every range, keeping the overlap policy.

    RangeSet::contains

    fn[K : Compare + Eq] RangeSet::contains(self : RangeSet[K], key : K) -> Bool

    Whether key is covered by a range.

    RangeSet::copy

    fn[K] RangeSet::copy(self : RangeSet[K]) -> RangeSet[K]

    A copy that owns its array: a change to either set is invisible to the other.

    RangeSet::equal

    fn[K : Eq] RangeSet::equal(self : RangeSet[K], other : RangeSet[K]) -> Bool

    RangeSet::gaps

    fn[K] RangeSet::gaps(self : RangeSet[K]) -> Iter[(K, K)]

    The spans between one range and the next, in order.

    RangeSet::insert

    fn[K : Compare + Eq] RangeSet::insert(self : RangeSet[K], start~ : K, end~ : K) -> Unit raise
    Refused

    Adds the range from start up to end, merging it with the ranges it touches.

    RangeSet::is_empty

    fn[K] RangeSet::is_empty(self : RangeSet[K]) -> Bool

    Whether the set holds no range.

    RangeSet::length

    fn[K] RangeSet::length(self : RangeSet[K]) -> Int

    How many ranges the set holds.

    RangeSet::new

    fn[K] RangeSet::new(overlap? : Overlap) -> RangeSet[K]

    An empty range set whose policy for an overlapping insert is overlap.

    RangeSet::not_equal

    fn[K : Eq] RangeSet::not_equal(x : RangeSet[K], y : RangeSet[K]) -> Bool

    RangeSet::output

    fn[K : Show] RangeSet::output(self : RangeSet[K], logger : &Logger) -> Unit

    RangeSet::overlapping

    fn[K : Compare + Eq] RangeSet::overlapping(self : RangeSet[K], start~ : K, end~ : K) -> Array[(K, K)]

    The ranges that meet the span from start up to end, in order.

    RangeSet::ranges

    fn[K] RangeSet::ranges(self : RangeSet[K]) -> Iter[(K, K)]

    The ranges, in order.

    RangeSet::remove

    fn[K : Compare + Eq] RangeSet::remove(self : RangeSet[K], start~ : K, end~ : K) -> Unit

    Removes the span from start up to end, cutting the ranges that cover it.

    RangeSet::to_string

    fn[K : Show] RangeSet::to_string(self : RangeSet[K]) -> String

    SortedMultiMap

    pub struct SortedMultiMap[K, V] {
    entries : Array[(K, V)]
    }

    A multimap held as a sorted array: the keys are in order, and the values of one key are in order among themselves as well, so range and first walk the pairs in the order a reader expects.

    test {
    let map : @map.SortedMultiMap[Int32, String] = @map.SortedMultiMap::new()
    map.insert(2, "b")
    map.insert(1, "a")
    map.insert(1, "b")
    @test.assert_eq(map.first(), Some((1, "a")))
    @test.assert_eq(map.get(1), ["a", "b"])
    }
    impl Eq for SortedMultiMap[K, V]
    impl Show for SortedMultiMap[K, V]

    SortedMultiMap::clear

    fn[K, V] SortedMultiMap::clear(self : SortedMultiMap[K, V]) -> Unit

    Removes every entry.

    SortedMultiMap::contains

    fn[K : Compare + Eq, V] SortedMultiMap::contains(self : SortedMultiMap[K, V], key : K) -> Bool

    Whether key has at least one value.

    SortedMultiMap::copy

    fn[K, V] SortedMultiMap::copy(self : SortedMultiMap[K, V]) -> SortedMultiMap[K, V]

    A copy that owns its array: a change to either multimap is invisible to the other.

    SortedMultiMap::equal

    fn[K : Eq, V : Eq] SortedMultiMap::equal(self : SortedMultiMap[K, V], other : SortedMultiMap[K, V]) -> Bool

    SortedMultiMap::first

    fn[K, V] SortedMultiMap::first(self : SortedMultiMap[K, V]) -> (K, V)?

    The smallest entry, or None when the map is empty.

    SortedMultiMap::get

    fn[K : Compare + Eq, V] SortedMultiMap::get(self : SortedMultiMap[K, V], key : K) -> Array[V]

    The values of key, in order.

    SortedMultiMap::insert

    fn[K : Compare + Eq, V : Compare + Eq] SortedMultiMap::insert(self : SortedMultiMap[K, V], key : K, value : V) -> Unit

    Adds value under key; the entry goes where key order puts it, and equal keys keep the values in the order they were added.

    SortedMultiMap::is_empty

    fn[K, V] SortedMultiMap::is_empty(self : SortedMultiMap[K, V]) -> Bool

    Whether no value is stored under any key.

    SortedMultiMap::iter

    fn[K, V] SortedMultiMap::iter(self : SortedMultiMap[K, V]) -> Iter[(K, V)]

    Every entry in key order, and within one key in the order the values were added.

    SortedMultiMap::key_count

    fn[K : Compare + Eq, V] SortedMultiMap::key_count(self : SortedMultiMap[K, V]) -> Int

    The number of distinct keys.

    SortedMultiMap::last

    fn[K, V] SortedMultiMap::last(self : SortedMultiMap[K, V]) -> (K, V)?

    The largest entry, or None when the map is empty.

    SortedMultiMap::length

    fn[K, V] SortedMultiMap::length(self : SortedMultiMap[K, V]) -> Int

    How many entries, counting one per value, the map holds.

    SortedMultiMap::new

    fn[K, V] SortedMultiMap::new() -> SortedMultiMap[K, V]

    An empty multimap that keeps its entries in key order.

    SortedMultiMap::not_equal

    fn[K : Eq, V : Eq] SortedMultiMap::not_equal(x : SortedMultiMap[K, V], y : SortedMultiMap[K, V]) -> Bool

    SortedMultiMap::output

    fn[K : Show, V : Show] SortedMultiMap::output(self : SortedMultiMap[K, V], logger : &Logger) -> Unit

    SortedMultiMap::pop_first

    fn[K, V] SortedMultiMap::pop_first(self : SortedMultiMap[K, V]) -> (K, V)?

    Removes and returns the smallest entry.

    SortedMultiMap::pop_last

    fn[K, V] SortedMultiMap::pop_last(self : SortedMultiMap[K, V]) -> (K, V)?

    Removes and returns the largest entry.

    SortedMultiMap::range

    fn[K : Compare + Eq, V] SortedMultiMap::range(self : SortedMultiMap[K, V], start~ : K, end~ : K) -> Iter[(K, V)]

    The pairs whose keys fall in start up to end, both included.

    SortedMultiMap::remove

    fn[K : Compare + Eq, V] SortedMultiMap::remove(self : SortedMultiMap[K, V], key : K) -> Array[V]

    Drops the values of key and returns them.

    SortedMultiMap::to_array

    fn[K, V] SortedMultiMap::to_array(self : SortedMultiMap[K, V]) -> Array[(K, V)]

    Every entry in key order, as a new array.

    SortedMultiMap::to_string

    fn[K : Show, V : Show] SortedMultiMap::to_string(self : SortedMultiMap[K, V]) -> String

    Trie

    pub struct Trie[T] {
    children : Array[Map[Char, Int]]
    values : Array[T?]
    entries : Int
    }

    A map keyed by String that shares the storage of keys with a common prefix: the walk to a key costs one step per character, whatever else is stored.

    test {
    let trie : @map.Trie[Int32] = @map.Trie::new()
    @test.assert_eq(trie.insert("car", 1), None)
    @test.assert_eq(trie.insert("cart", 2), None)
    @test.assert_eq(trie.get("car"), Some(1))
    @test.assert_eq(trie.keys_with_prefix("ca"), ["car", "cart"])
    @test.assert_eq(trie.longest_prefix("cartoon"), Some(("cart", 2)))
    }
    impl Show for Trie[T]

    Trie::clear

    fn[T] Trie::clear(self : Trie[T]) -> Unit

    Removes every word, leaving the root.

    Trie::contains

    fn[T] Trie::contains(self : Trie[T], key : StringView) -> Bool

    Whether key is a stored word; a prefix of one is not.

    Trie::contains_prefix

    fn[T] Trie::contains_prefix(self : Trie[T], prefix : StringView) -> Bool

    Whether any key stored here starts with prefix.

    Trie::copy

    fn[T] Trie::copy(self : Trie[T]) -> Trie[T]

    A copy that shares nothing with the original: a write to either is invisible to the other.

    Trie::get

    fn[T] Trie::get(self : Trie[T], key : StringView) -> T?

    The value stored under key, or None when key is not a stored word.

    Trie::insert

    fn[T] Trie::insert(self : Trie[T], key : StringView, value : T) -> T?

    Stores value under key and returns the value the key held before.

    Trie::is_empty

    fn[T] Trie::is_empty(self : Trie[T]) -> Bool

    Whether no word is stored.

    Trie::iter

    fn[T] Trie::iter(self : Trie[T]) -> Iter[(String, T)]

    Every pair, in key order.

    Trie::keys_with_prefix

    fn[T] Trie::keys_with_prefix(self : Trie[T], prefix : StringView) -> Array[String]

    The keys starting with prefix, in character order.

    Trie::length

    fn[T] Trie::length(self : Trie[T]) -> Int

    The number of keys that carry a value.

    Trie::longest_prefix

    fn[T] Trie::longest_prefix(self : Trie[T], text : StringView) -> (String, T)?

    The longest key stored here that is a prefix of text, with its value.

    Trie::new

    fn[T] Trie::new() -> Trie[T]

    An empty trie, holding no key.

    Trie::output

    fn[T : Show] Trie::output(self : Trie[T], logger : &Logger) -> Unit

    Trie::remove

    fn[T] Trie::remove(self : Trie[T], key : StringView) -> T?

    Drops the value under key and returns it. The nodes stay, so a later insert of a key with the same prefix does not walk the string again.

    Trie::to_array

    fn[T] Trie::to_array(self : Trie[T]) -> Array[(String, T)]

    Every stored word and its value, in the depth-first order the trie walks.

    Trie::to_string

    fn[T : Show] Trie::to_string(self : Trie[T]) -> String