forall K, V, 'k.
struct HashMap! { ... }
A hash map that owns its keys and values, under brand 'k, hashing them under the seed it was made with (core::hash).
alloc/back describe the bucket array only. The per-entry K, V and Entry allocations are single-value blocks reached through raw pointers, freed by free_one, take_chain and destroy_chain, and are not under a domain. The bucket array's free takes its address from alloc, never from a Ref.
Methods
method try_newsource
fn try_new(seed: Seed) -> Result[exists '1. (Exclusive!['1], HashMap![K, V, '1]), AllocError] { ... }
An empty map with 8 buckets, under a fresh brand, that hashes its keys under seed, or the allocation failure. Growing it later (insert, which also allocates every entry) aborts on failure.
method newsource
fn new(seed: Seed) -> exists '1. (Exclusive!['1], HashMap![K, V, '1]) { ... }
An empty map with 8 buckets, under a fresh brand, that hashes its keys under seed: try_new, aborting on failure.
method lensource
fn len(&self) -> usize { ... }
How many entries the map holds. The count is the map's own field, not a read of its storage, so no capability is presented.
method is_emptysource
fn is_empty(&self) -> bool { ... }
Whether the map holds no entries.
method destroy_withsource
fn destroy_with(self, tag: Exclusive!['k], f: fn(K, V) -> ()) -> () { ... }
Consumes the map: calls f once per (key, value) pair, then frees every entry and the bucket array. The array's free takes its address from alloc, recorded by Allocation!::adopt; the per-entry frees in destroy_chain go through raw *K/*V/*Entry pointers.
method get_insource
forall C where HashIn[K, C].
fn get_in(&self, &tag: Exclusive!['k], &cx: C, key: K) -> Option[Ref[V, 'k]] { ... }
The value stored under a domain key, if any. This is get for a Copy key that points into a domain, hashed and compared through that domain's capability cx (lent by place).
method contains_insource
forall C where HashIn[K, C].
fn contains_in(&self, &tag: Exclusive!['k], &cx: C, key: K) -> bool { ... }
Whether a domain key is in the map.
method insert_insource
forall C where HashIn[K, C].
fn insert_in(self, tag: Exclusive!['k], &cx: C, key: K, val: V) -> exists '2. (Exclusive!['2], HashMap![K, V, '2], Option[V]) { ... }
Stores val under the domain key key, handing back the value it replaces: insert for a domain key. The map comes back freshly branded, as from insert.
method remove_insource
forall C where HashIn[K, C].
fn remove_in(self, tag: Exclusive!['k], &cx: C, key: K) -> exists '2. (Exclusive!['2], HashMap![K, V, '2], Option[V]) { ... }
Removes a domain key's entry, handing back its value: remove for a domain key. The entry's storage is freed, so the map comes back freshly branded, as from remove, and no Ref from get_in survives the call.
method containssource
fn contains(&self, &tag: Exclusive!['k], &key: K) -> bool { ... }
Whether key is in the map.
method getsource
fn get(&self, &tag: Exclusive!['k], &key: K) -> Option[Ref[V, 'k]] { ... }
The value stored under key, if any.
method insertsource
fn insert(self, tag: Exclusive!['k], key: K, val: V) -> exists '2. (Exclusive!['2], HashMap![K, V, '2], Option[(K, V)]) { ... }
Stores val under key. When key was already present, the entry takes key and val, and the stored key and value come back. The bucket array may move, so the map comes back freshly branded.
method removesource
fn remove(self, tag: Exclusive!['k], &key: K) -> exists '2. (Exclusive!['2], HashMap![K, V, '2], Option[(K, V)]) { ... }
Removes the entry stored under key, handing back its stored key and value.
method findsource
forall Q where Hash[Q], Eq[K, Q].
fn find(&self, &tag: Exclusive!['k], &probe: Q) -> Option[Ref[V, 'k]] { ... }
Looks up by a probe of another type that hashes like the stored keys and compares equal to the one it stands for -- typically a borrowed view of an owned key (Readable for Buffer!, see core::borrow), so a lookup needs no owned key. The probe comes back.
method eachsource
forall Env where Copy[Env].
fn each(&self, &tag: Exclusive!['k], f: closure[Env](&_: K, &_: V) -> ()) { ... }
Calls f on each key and its value where they live, in no particular order: f gets both through &, and nothing is copied out or back. The map stays as it is, apart from what f does to the values. A key f changes stays in the bucket of its old hash, so a lookup may then miss it; nothing worse comes of it.
method each_insource
forall C, Env where Copy[Env].
fn each_in(&self, &tag: Exclusive!['k], &cx: C, f: closure[Env](&_: K, &_: V, &_: C) -> ()) { ... }
each, with a context cx lent to f beside each key and value: the linear values f works on, which it cannot capture (an output to write the entries to, say).
method clear_withsource
fn clear_with(self, tag: Exclusive!['k], f: fn(K, V) -> ()) -> exists '2. (Exclusive!['2], HashMap![K, V, '2]) { ... }
Removes every entry, handing each to f, and keeps the bucket array, so the map holds as many again without growing. The entries' storage is freed, so the map comes back freshly branded, as from remove.
method destroysource
fn destroy(self, tag: Exclusive!['k]) -> () { ... }
Frees a map of Copy keys and values, which need no per-entry callback.
method drainsource
fn drain(self, tag: Exclusive!['k]) -> Drain![K, V, 'k] { ... }
Every entry, as an Iterator of owned (key, value) pairs, in no particular order. Drain!::finish frees what is left.