std/map
Types
Map
pub type Map[K: Eq + Hash, V] = {
// slots is an open-addressing index of sequence number + 2 (0 free,
// 1 removed); its length is a power of two.
// seqList[pos] is the sequence number of entry pos after a removal; before that it is empty or the identity.
// meta is empty until the first insert, then [removals since the last reindex].
// private fields omitted
}
Map from K to V; keys need Eq and Hash. Entries keep insertion order.
Map.equals
pub pure fn Map[K: Eq + Hash, V: Eq].equals(self, other: &Map[K, V]) -> Bool
Same entries in any order; satisfies Eq when the values do.
Map.hash
pub pure fn Map[K: Eq + Hash, V: Hash].hash(self) -> u64
Hash over the entries in any order; satisfies Hash when the values do.
Map.clone
pub pure fn Map[K: Copy, V: Copy].clone(self) -> Map[K, V]
A copy of the map; keys and values are Copy, so nothing is shared.
Map.tryClone
pub pure fn Map[K: Copy, V: Copy].tryClone(self) -> Result[Map[K, V], AllocError]
A copy of the map, or AllocError when the allocator refuses (clone panics instead); the original is untouched either way.
Map.set
pub pure fn Map[K: Eq + Hash, V].set(mut self, key: K, value: V)
Inserts value under key, replacing an existing value.
Map.trySet
pub pure fn Map[K: Eq + Hash, V].trySet(mut self, key: K, value: V) -> Result[Void, AllocError]
Inserts value under key, or AllocError when the allocator refuses; the map is left unchanged in that case (set panics instead).
Map.get
pub pure fn Map[K: Eq + Hash, V: Copy].get(self, key: &K) -> V?
A copy of the value stored under key, or None when the key is absent.
Map.with
pub pure fn Map[K: Eq + Hash, V].with[R](self, key: &K, f: fn(&V) -> R) -> R?
Calls f with a borrow of the value under key; None when the key is absent.
Map.take
pub pure fn Map[K: Eq + Hash, V].take(mut self, key: &K) -> V?
Moves the value under key out of the map; None when the key is absent. The index slot is marked dead and the later entries shift down, so the cost is a copy of the tail rather than a rehash.
Map.len
pub pure noalloc fn Map[K, V].len(self) -> usize
Number of entries.
Map.entries
pub pure fn Map[K: Copy, V: Copy].entries(self) -> Array[Entry[K, V]]
Copies of all entries in insertion order.
Map.tryEntries
pub pure fn Map[K: Copy, V: Copy].tryEntries(self) -> Result[Array[Entry[K, V]], AllocError]
Copies of all entries in insertion order, or AllocError when the allocator refuses (entries panics instead).
Map.contains
pub pure fn Map[K: Eq + Hash, V].contains(self, key: &K) -> Bool
Whether key is present.
Map.remove
pub pure fn Map[K: Eq + Hash, V].remove(mut self, key: &K)
Removes key and drops its value; does nothing when the key is absent.
Map.keys
pub pure fn Map[K: Copy, V].keys(self) -> Array[K]
Copies of all keys in insertion order; the values stay untouched.
Map.tryKeys
pub pure fn Map[K: Copy, V].tryKeys(self) -> Result[Array[K], AllocError]
Copies of all keys in insertion order, or AllocError when the allocator refuses (keys panics instead).
Map.values
pub pure fn Map[K: Copy, V: Copy].values(self) -> Array[V]
Copies of all values in insertion order.
Map.tryValues
pub pure fn Map[K: Copy, V: Copy].tryValues(self) -> Result[Array[V], AllocError]
Copies of all values in insertion order, or AllocError when the allocator refuses (values panics instead).
Entry
pub type Entry[K, V] = {
pub key K
pub value V
}
One key/value pair of a map, as returned by entries.
Functions
empty
pub pure fn empty[K: Eq + Hash, V]() -> Map[K, V]
Creates an empty map.
tryEmpty
pub pure fn tryEmpty[K: Eq + Hash, V]() -> Result[Map[K, V], AllocError]
Creates an empty map, or AllocError when the allocator refuses (empty panics instead).