Import std.collections.immutable
std.collections.immutable
Arrays, maps, and sets that never change, so any thread can read them.
ImmutableArray<T>, ImmutableMap<K, V>, and ImmutableSet<T>: collections that never change,
so any thread can read one. A change gives a new collection, which shares all of the old one's
nodes but the ones on the way down to what changed, in a balanced tree, about log(Count) of
them. Their values are Sendable, as the collections are.
std/collections/immutable.fb
Types
ImmutableArray
struct
@DebugElements Public Struct ImmutableArray<T: Sendable> Implements Iterable<T>, Defaultable, Sendable
An array that never changes: each change gives a new one, which shares what it can with the old, so threads can share it.
Examples
Local first = ImmutableArray<Int>().AddAll([1, 2, 3])
Local second = first.Set(0, 10).Add(4)
Expect(first.ToArray() == [1, 2, 3])
Expect(second.ToArray() == [10, 2, 3, 4])std/collections/immutable.fb, line 41
-
An empty one.
-
One with the
values, in order, all read first. -
How many values it holds.
-
The value at
index, which panics outside it. -
A copy with
valueatindexin place of what's there. -
A copy with
valueadded at the end. -
A copy with each of the
valuesadded at the end, in order, all read first. -
A copy with
valueatindex, moving what's there and after it along, whereindexis from 0 to Count. -
A copy without the value at
index. -
Whether it holds
value. -
The values, in order, in a new array.
-
An empty one.
-
The values, in order.
ImmutableArrayIterator
struct
Public Struct ImmutableArrayIterator<T: Sendable> Implements Iterator<T>
The values of an ImmutableArray, in order, which a For loop goes over.
std/collections/immutable.fb, line 258
-
The next value, in order, or Null after the last.
ImmutableMap
struct
@DebugEntries Public Struct ImmutableMap<K, V> Implements Iterable<(K, V)>, Defaultable, Sendable
A Map that never changes: each change gives a new one, which shares what it can with the old, so threads can share it.
Examples
Local empty = ImmutableMap<String, Int>()
Local ages = empty.Add("Ada", 36).Add("Alan", 41)
Expect(empty.Count == 0 && ages.Count == 2)
Expect(ages.Get("Ada") == 36)
Expect(!ages.Remove("Ada").Contains("Ada") && ages.Contains("Ada"))std/collections/immutable.fb, line 372
-
An empty one.
-
One with the
entries, all read first, a second entry's value for a key taking the place of an earlier one's. -
How many entries it holds.
-
The
key's value, or Null when it isn't there. -
The
key's value, orfallbackwhen it isn't there. -
The key's value. A key that isn't there panics.
-
Whether
keyhas an entry. -
A copy with the
key'svalue, which takes the place of the one it has. -
A copy with each of the
entriesadded in turn, as Add adds one, all read first. -
A copy without the
key's entry, or the same one when it has none. -
The keys, in the order the entries go in.
-
The values, in their keys' order.
-
A new Map with the same entries, in the same order.
-
An empty one.
-
Each key and its value, for 'For key, value In map', by their keys' hashes, and keys of one hash in the order they were added.
ImmutableMapIterator
struct
Public Struct ImmutableMapIterator<K, V> Implements Iterator<(K, V)>
The entries of an ImmutableMap, in its order, which a For loop goes over.
std/collections/immutable.fb, line 658
-
The next key and its value, in the ImmutableMap's order, or Null after the last.
ImmutableSet
struct
@DebugElements Public Struct ImmutableSet<T> Implements Iterable<T>, Defaultable, Sendable, Hashable
A Set that never changes: each change gives a new one, which shares what it can with the old, so threads can share it.
Examples
Local a = ImmutableSet<Int>().AddAll([1, 2])
Local b = a.Add(3)
Expect(a.Count == 2 && b.Count == 3)
Expect(b.Contains(3) && !a.Contains(3))std/collections/immutable.fb, line 750
-
An empty one.
-
One with the
values, all read first. -
How many values it holds.
-
Whether it holds
value. -
A copy with the
value, or the same one when it has it. -
A copy with each of the
valuesadded, all read first. -
A copy without the
value, or the same one when it hasn't got it. -
The values, in a new array, in the order they go in.
-
An empty one.
-
Two ImmutableSets are equal when they have the same values.
-
Equal ImmutableSets have equal hashes, whatever order their values go in.
-
The values, by their hashes, and values of one hash in the order they were added.
ImmutableSetIterator
struct
Public Struct ImmutableSetIterator<T> Implements Iterator<T>
The values of an ImmutableSet, which a For loop goes over.
std/collections/immutable.fb, line 819
-
The next value, in the ImmutableSet's order, or Null after the last.
Extends
ImmutableArray
extend
Extend ImmutableArray<T> Implements Equatable
Compares ImmutableArrays with == and !=, where their values can be compared.
std/collections/immutable.fb, line 282
-
Whether the two have equal values in the same order.
ImmutableArray
extend
Extend ImmutableArray<T> Implements Hashable
Hashes an ImmutableArray, where its values can be hashed, so it can be a Map's key or a Set's value.
std/collections/immutable.fb, line 299
-
A hash of its values in order, which ImmutableArrays that are equal share.
ImmutableArray
extend
Extend ImmutableArray<T> Implements Printable
Shows an ImmutableArray in a string, as its ToString writes it.
std/collections/immutable.fb, line 314
-
Its values, in order, as an array shows them: "[1, 2, 3]".
ImmutableMap
extend
Extend ImmutableMap<K, V> Implements Equatable
Compares ImmutableMaps with == and !=, where their values can be compared.
std/collections/immutable.fb, line 693
-
Whether the two have the same keys, each with an equal value.
ImmutableMap
extend
Extend ImmutableMap<K, V> Implements Hashable
Hashes an ImmutableMap, where its keys and values can be hashed, so it can be a Map's key or a Set's value.
std/collections/immutable.fb, line 710
-
A hash of its entries, whatever their order, which ImmutableMaps that are equal share.
ImmutableMap
extend
Extend ImmutableMap<K, V> Implements Printable
Shows an ImmutableMap in a string, as its ToString writes it.
std/collections/immutable.fb, line 725
-
Its entries, in its order, as a Map shows them: "{a: 1, b: 2}".
ImmutableSet
extend
Extend ImmutableSet<T> Implements Printable
Shows an ImmutableSet in a string, as its ToString writes it.
std/collections/immutable.fb, line 835
-
Its values, in its order, as a Set shows them: "{1, 2, 3}".
Report an issue with this page or with FutureBlitz on GitHub.