forall K, V, 'k.
struct ArenaMap { ... }
A hash map in an arena, its keys in insertion order: a Copy handle whose copies all name the same map.
Methods
method newsource
forall C, R where Allocate[C -> 'k, R].
fn new(&cx: C) -> ArenaMap[K, V, 'k] { ... }
An empty map in the context's arena.
method lensource
forall C, R where Access[C -> 'k, R].
fn len(self, &cx: C) -> usize { ... }
How many keys are in the map.
method is_emptysource
forall C, R where Access[C -> 'k, R].
fn is_empty(self, &cx: C) -> bool { ... }
Whether the map holds no keys.
method addresssource
fn address(self) -> usize { ... }
The map's identity: equal for copies of one map, different for different maps.
method positionssource
forall C, R where Access[C -> 'k, R].
fn positions(self, &cx: C) -> usize { ... }
The number of positions key_at reads: one per key inserted since grow last dropped dead entries, in insertion order. Reading positions 0..positions() visits the keys as keys lists them; removing a key meanwhile only empties its position, but inserting a new key may renumber them (grow).
method key_atsource
forall C, R where Access[C -> 'k, R].
fn key_at(self, &cx: C, i: usize) -> Option[K] { ... }
The key at a position, unless it was removed.
method eachsource
forall Env, C, R where Access[C -> 'k, R], Copy[Env].
fn each(self, &cx: C, f: closure[Env](&_: C, K, V) -> ()) { ... }
f on each key and its value, for what it does through the context.
method anysource
forall Env, C, R where Access[C -> 'k, R], Copy[Env].
fn any(self, &cx: C, f: closure[Env](&_: C, K, V) -> bool) -> bool { ... }
Whether f holds for some key and its value.
method allsource
forall Env, C, R where Access[C -> 'k, R], Copy[Env].
fn all(self, &cx: C, f: closure[Env](&_: C, K, V) -> bool) -> bool { ... }
Whether f holds for every key and its value.
method keyssource
forall C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q].
fn keys(self, &cx: C) -> ArenaVec[K, 'k] { ... }
The live keys, in insertion order, in a new vec.
method valuessource
forall C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q].
fn values(self, &cx: C) -> ArenaVec[V, 'k] { ... }
The values, in their keys' insertion order, in a new vec.
method slotsource
forall C, R where Access[C -> 'k, R], HashIn[K, C].
fn slot(self, &cx: C, slots: Slice[usize, 'k], entries: ArenaVec[Entry[K, V], 'k], key: K, hash: u32) -> (usize, usize) { ... }
The slot holding key, whose hash bits are hash, or the empty slot where it would go, and what that slot holds.
method indexsource
forall C, R where Access[C -> 'k, R], HashIn[K, C].
fn index(self, &cx: C, key: K) -> Option[usize] { ... }
The position of a live key.
method containssource
forall C, R where Access[C -> 'k, R], HashIn[K, C].
fn contains(self, &cx: C, key: K) -> bool { ... }
Whether key is in the map.
method getsource
forall C, R where Access[C -> 'k, R], HashIn[K, C].
fn get(self, &cx: C, key: K) -> Option[V] { ... }
The value of key, or None when it is not in the map.
method atsource
forall C, R where Access[C -> 'k, R], HashIn[K, C].
fn at(self, &cx: C, key: K) -> V { ... }
The value of a key that must be in the map: without it, the process stops (core::process::trap).
method get_orsource
forall C, R where Access[C -> 'k, R], HashIn[K, C].
fn get_or(self, &cx: C, key: K, default: V) -> V { ... }
The value of key, or default when it is not in the map.
method insertsource
forall C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q], HashIn[K, C].
fn insert(self, &cx: C, key: K, value: V) -> Option[V] { ... }
Maps key to value, handing back the value it replaces, if any. A key already present is replaced, key and value, as alloc::collections::hashmap replaces one, and keeps its place in the order; a new key goes at the end, and so does a removed one coming back.
method get_or_insertsource
forall C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q], HashIn[K, C].
fn get_or_insert(self, &cx: C, key: K, default: V) -> V { ... }
The value of key; when it is not in the map, default is inserted under it first.
method upsertsource
forall Env, C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q], HashIn[K, C], Copy[Env].
fn upsert(self, &cx: C, key: K, default: V, f: closure[Env](&_: C, V) -> V) -> V { ... }
Maps key to f of its value, or of default when it is not in the map, and returns the new value. f is lent the context, as the combinators are. (update, elsewhere, lends a value in place.)
method removesource
forall C, R where Access[C -> 'k, R], HashIn[K, C].
fn remove(self, &cx: C, key: K) -> Option[V] { ... }
Takes key out of the map, handing back its value, if it was there.
method growsource
forall C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q].
fn grow(self, &cx: C, slot_count: usize) { ... }
Makes the slots again, at least slot_count of them, every live key placed again by its hash bits. Their number is a power of two, at least 8 and more than twice the entries, whatever slot_count asks for, so the next insertion has room; the slots the map has are emptied and used again when there are that many, and the arena gives new ones otherwise. When more entries are dead than live, the dead ones are dropped first, the live ones keeping their order; positions (key_at) then count the live entries only.
method retainsource
forall Env, C, R where Access[C -> 'k, R], Copy[Env].
fn retain(self, &cx: C, f: closure[Env](&_: C, K, V) -> bool) { ... }
Keeps the entries f holds for, in their order, and removes the rest.
f is lent the context, so it can change the map through a copy of its handle. The entries are visited by position as they stand after each call, and an entry f rejects is removed only if it is still live there; the count is the map's own at each removal, so it stays the number of live keys whatever f did. An insertion that makes the map drop its dead entries (grow) moves the live ones, so a call after it sees the entries from their new positions on.
method clonesource
forall C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q].
fn clone(self, &cx: C) -> ArenaMap[K, V, 'k] { ... }
The same live entries, in the same order, in a map of their own.
method clearsource
forall C, R where Access[C -> 'k, R].
fn clear(self, &cx: C) { ... }
Removes every key, keeping the room the map has for the keys inserted next. Slots far more than its entries need are let go, so that clearing costs in proportion to what the map held: a map that once held many keys does not empty all their slots every time.
method assignsource
forall C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q].
fn assign(self, &cx: C, other: ArenaMap[K, V, 'k]) { ... }
Makes the map hold other's live entries, in their order, in the room it already has: its entries are refilled in place, and its slots are cleared and kept while they are enough. A map loaded again and again (a scratch state) takes new room only to hold more keys than it has held before.