Import std.collections.map
std.collections.map
A hash map that keeps its entries 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 32
-
A new, empty Map.
-
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.
-
How many entries it holds.
-
Adds an entry, or gives an existing
keyits new value. -
Adds an entry when the
keyisn't there, and tells whether it wasn't. -
Adds each of
other's entries, in its order, as Add does. -
The
key's value, or Null when it isn't there. -
The
key's value, orfallbackwhen it isn't there. -
The
key's value, adding whatmakegives for it first when it isn't there, which is thekey's value thoughmakeadded thekeyitself.Examples
Local groups = Map<String, Int[]>() groups.GetOrAdd("odd", Function(): Int[] => []).Add(1) groups.GetOrAdd("odd", Function(): Int[] => []).Add(3) Expect(groups["odd"] == [1, 3]) -
Gives the
key's value whatchangegives for it, and tells whether thekeywas there. A key thatchangeremoved stays removed.Examples
Local stock = {"apples": 3} Expect(stock.Update("apples", Function(n: Int) => n - 1)) Expect(!stock.Update("pears", Function(n: Int) => n - 1)) Expect(stock["apples"] == 2) -
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.
-
Gives the key a value, adding it when it isn't there.
-
Whether
keyhas an entry. -
Removes the
key's entry, and tells whether there was one. The others keep their order. -
Removes each entry that
testsays to, and tells how many went. -
Takes every entry out.
-
Makes room for
countentries in all, so adding up to that many doesn't move them again. -
Its keys, in order, in a new array.
-
Its values, in order, in a new array.
-
A new, empty Map.
-
A new Map with the same entries, in the same order, and the same default.
-
A new Map of the entries that
keepsays to keep. -
The first entry that
testsays is the one, or Null. -
Whether
testsays yes for any entry, going no further than the first. -
A new Map of the same keys, in the same order, each with what
changegives for its value. -
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 a For loop goes over.
std/collections/map.fb, line 424
-
The next key and its value, in the order they were added, or Null after the last. Panics when the Map changed since the loop began.
Extends
Map
extend
Extend Map<K, V> Implements Equatable
Compares Maps with == and !=, where their values can be compared.
std/collections/map.fb, line 446
-
Whether the two have the same keys, each with an equal value, whatever order they were added in.
Map
extend
Extend Map<K, V> Implements Hashable
Hashes a Map, where its keys and values can be hashed, so it can be a Map's key or a Set's value.
std/collections/map.fb, line 464
-
A hash of its entries, whatever order they were added in, which Maps that are equal share.
Map
extend
Extend Map<K, V> Implements Printable
Shows a Map in a string, as its ToString writes it.
std/collections/map.fb, line 479
-
Its entries, in order, as "{a: 1, b: 2}".
Report an issue with this page or with FutureBlitz on GitHub.