Re-exported from alloc::collections::hashmap.
Owning hash maps and sets with separate chaining.
Types
Entry | One key and value of a bucket's chain, and the next entry in it. |
HashMap! | A hash map that owns its keys and values, under brand 'k, hashing them under the seed it was made with (core::hash). |
Drain! | The map being taken apart: the bucket being walked, and the entry in it that comes next. |
OwnedMap! | A HashMap! packaged with its capability, for a map kept across calls or in a loop variable without naming its brand. |
Functions
try_alloc_buckets | Allocates a bucket array of n null slots and hands back the block itself along with its base. |
alloc_buckets | try_alloc_buckets, aborting on failure. |
alloc_one | A single value in its own allocation; used for both keys and values (see the header for why neither lives inline in Entry). |
free_one | Frees what alloc_one allocated for p. |
alloc_entry | A chain entry holding key, val and next, in its own allocation. |
destroy_chain | Calls f once per entry (so linear K/V can be consumed), then frees that entry's key, value and node allocations, walking the chain in a loop. |
hash_key | The hash of the key k, which is lent, under seed. |
keys_equal | Whether the stored key at a equals b; both are put back. |
find_chain | The value block of the entry in the chain at head whose key equals key, if any. |
put_chain | Stores val under the key at key_ptr, at the end of the chain when it is new. |
take_chain | Unlinks the entry whose key equals key, handing back its stored key and value. |
rehash_bucket_hashed | Moves every entry of the chain at head to its bucket among the new_bc at new_base. |
resize_hashed | A bucket array twice as long as the old_bc at base, every entry moved into it, and its length; frees the old array u_old. |
hash_key_in | The hash of the domain key key under seed, read through cx. |
find_chain_in | find_chain for a domain key, compared through cx. |
put_chain_in | Stores val under key, at the end of the chain when it is new; an entry already there takes key and val and hands back its value. |
take_chain_in | Unlinks key's entry, handing back its value. |
link_after | The chain head with rest linked after last, or rest itself when last is null (rest then replaces the chain's start). |
rehash_bucket_in | rehash_bucket_hashed for domain keys, hashed through cx. |
resize_in | resize_hashed for domain keys, hashed through cx. |
key_matches | Whether the stored key at k equals the probe q; both are put back. |
find_chain_by | find_chain by a probe of another type (Eq[K, Q]). |
forget_entry | Lets a Copy key and value go: the callback destroy and clear pass to destroy_with and clear_with. |
Instances
Iterator[Drain![K, V, 'k] -> Pair[K, V]] | The drained entries, each moved out as Pair { a: key, b: value }. |
Function declarations
fn try_alloc_bucketssource
forall K, V.
unsafe fn try_alloc_buckets(n: usize) -> Result[(Uninit!, *(*Entry[K, V])), AllocError] { ... }
Allocates a bucket array of n null slots and hands back the block itself along with its base. Returning the Uninit! rather than a bare pointer lets the caller pass it straight to Allocation!::adopt (the only producer of an Allocation!) without re-stating a size; the into_parts/adopt_raw_sized round trip keeps the extent the allocator recorded. The allocation failure, when there is no block. Caller: uses base only while the returned block, or the record that adopts it, owns the storage.
fn alloc_bucketssource
forall K, V.
unsafe fn alloc_buckets(n: usize) -> (Uninit!, *(*Entry[K, V])) { ... }
try_alloc_buckets, aborting on failure. Caller: as for try_alloc_buckets.
fn alloc_onesource
forall T where Sized[T].
unsafe fn alloc_one(v: T) -> *T { ... }
A single value in its own allocation; used for both keys and values (see the header for why neither lives inline in Entry). Caller: frees the block once, through free_one or an entry's teardown, after moving the value out or letting it go only if it is Copy.
fn free_onesource
forall T.
unsafe fn free_one(p: *T) -> () { ... }
Frees what alloc_one allocated for p. Caller: p came from alloc_one, is freed once, and holds no value still owed to anyone (moved out, or Copy).
fn alloc_entrysource
forall K, V.
unsafe fn alloc_entry(key: *K, val: *V, next: *Entry[K, V]) -> *Entry[K, V] { ... }
A chain entry holding key, val and next, in its own allocation. Caller: key and val are blocks from alloc_one that the entry now owns, and next is null or an entry of the same chain. Used by put_chain and put_chain_in; not meant for direct use.
fn destroy_chainsource
forall K, V where Sized[K], Sized[V].
unsafe fn destroy_chain(head: *Entry[K, V], f: fn(K, V) -> ()) -> () { ... }
Calls f once per entry (so linear K/V can be consumed), then frees that entry's key, value and node allocations, walking the chain in a loop. Caller: head is null or the first entry of a chain of live entries the map owns, which nothing else touches during the call, and no entry of it is reached again.
fn hash_keysource
forall K where Hash[K].
fn hash_key(seed: Seed, &k: K) -> u64 { ... }
The hash of the key k, which is lent, under seed.
fn keys_equalsource
forall K where Eq[K, K], Sized[K].
unsafe fn keys_equal(a: *K, &b: K) -> bool { ... }
Whether the stored key at a equals b; both are put back. Caller: a is a live key block nothing else touches during the call.
fn find_chainsource
forall K, V where Eq[K, K], Sized[K].
unsafe fn find_chain(head: *Entry[K, V], &key: K) -> Option[*V] { ... }
The value block of the entry in the chain at head whose key equals key, if any. Caller: head is null or the first entry of a chain of live entries the map owns, which nothing else touches during the call. Used by HashMap!::get and contains; not meant for direct use.
fn put_chainsource
forall K, V where Eq[K, K], Sized[K], Sized[V].
unsafe fn put_chain(head: *Entry[K, V], key_ptr: *K, val: V) -> (*Entry[K, V], Option[(K, V)], bool) { ... }
Stores val under the key at key_ptr, at the end of the chain when it is new. When the key was already present, the entry takes the given key and value, and the ones it held come back. The chain's new head, and whether an entry was added. Caller: head is null or the first entry of a chain of live entries the map owns, which nothing else touches during the call; key_ptr is an alloc_one block the chain now owns.
fn take_chainsource
forall K, V where Eq[K, K], Sized[K], Sized[V].
unsafe fn take_chain(head: *Entry[K, V], &key: K) -> (*Entry[K, V], Option[(K, V)], bool) { ... }
Unlinks the entry whose key equals key, handing back its stored key and value. key is lent, and comes back. The chain's new head, and whether an entry was removed. Caller: head is null or the first entry of a chain of live entries the map owns, which nothing else touches during the call.
fn rehash_bucket_hashedsource
forall K, V where Hash[K], Sized[K].
unsafe fn rehash_bucket_hashed(seed: Seed, head: *Entry[K, V], new_base: *(*Entry[K, V]), new_bc: usize) -> () { ... }
Moves every entry of the chain at head to its bucket among the new_bc at new_base. Caller: head is null or the first entry of a chain of live entries the map owns, which nothing else touches during the call; new_base holds new_bc live slots. Used by resize_hashed; not meant for direct use.
fn resize_hashedsource
forall K, V where Hash[K], Sized[K].
unsafe fn resize_hashed(seed: Seed, u_old: Uninit!, base: *(*Entry[K, V]), old_bc: usize) -> (Uninit!, usize) { ... }
A bucket array twice as long as the old_bc at base, every entry moved into it, and its length; frees the old array u_old. Caller: u_old is the map's bucket array, released from its record, and base its base, holding old_bc chains the map owns. Used by HashMap!::insert; not meant for direct use.
fn hash_key_insource
forall K, C where Copy[K], HashIn[K, C].
fn hash_key_in(&cx: C, seed: Seed, key: K) -> u64 { ... }
The hash of the domain key key under seed, read through cx. Used by the _in operations; not meant for direct use.
fn find_chain_insource
forall K, V, C where Copy[K], HashIn[K, C], Sized[K].
unsafe fn find_chain_in(&cx: C, head: *Entry[K, V], key: K) -> Option[*V] { ... }
find_chain for a domain key, compared through cx. Caller: head is null or the first entry of a chain of live entries the map owns, which nothing else touches during the call. Used by HashMap!::get_in and contains_in; not meant for direct use.
fn put_chain_insource
forall K, V, C where Copy[K], HashIn[K, C], Sized[K], Sized[V].
unsafe fn put_chain_in(&cx: C, head: *Entry[K, V], key: K, val: V) -> (*Entry[K, V], Option[V], bool) { ... }
Stores val under key, at the end of the chain when it is new; an entry already there takes key and val and hands back its value. Caller: head is null or the first entry of a chain of live entries the map owns, which nothing else touches during the call.
fn take_chain_insource
forall K, V, C where Copy[K], HashIn[K, C], Sized[K], Sized[V].
unsafe fn take_chain_in(&cx: C, head: *Entry[K, V], key: K) -> (*Entry[K, V], Option[V], bool) { ... }
Unlinks key's entry, handing back its value. Caller: head is null or the first entry of a chain of live entries the map owns, which nothing else touches during the call.
fn link_aftersource
forall K, V.
unsafe fn link_after(head: *Entry[K, V], last: *Entry[K, V], rest: *Entry[K, V]) -> *Entry[K, V] { ... }
The chain head with rest linked after last, or rest itself when last is null (rest then replaces the chain's start). Caller: last is null or a live entry of the chain at head.
fn rehash_bucket_insource
forall K, V, C where Copy[K], HashIn[K, C], Sized[K].
unsafe fn rehash_bucket_in(&cx: C, seed: Seed, head: *Entry[K, V], new_base: *(*Entry[K, V]), new_bc: usize) -> () { ... }
rehash_bucket_hashed for domain keys, hashed through cx. Caller: as for rehash_bucket_hashed. Used by resize_in; not meant for direct use.
fn resize_insource
forall K, V, C where Copy[K], HashIn[K, C], Sized[K].
unsafe fn resize_in(&cx: C, seed: Seed, u_old: Uninit!, base: *(*Entry[K, V]), old_bc: usize) -> (Uninit!, usize) { ... }
resize_hashed for domain keys, hashed through cx. Caller: as for resize_hashed. Used by HashMap!::insert_in; not meant for direct use.
fn key_matchessource
forall K, Q where Eq[K, Q], Sized[K].
unsafe fn key_matches(k: *K, &q: Q) -> bool { ... }
Whether the stored key at k equals the probe q; both are put back. Caller: k is a live key block nothing else touches during the call.
fn find_chain_bysource
forall K, V, Q where Eq[K, Q], Sized[K].
unsafe fn find_chain_by(head: *Entry[K, V], &probe: Q) -> Option[*V] { ... }
find_chain by a probe of another type (Eq[K, Q]). Caller: head is null or the first entry of a chain of live entries the map owns, which nothing else touches during the call. Used by HashMap!::find; not meant for direct use.
fn forget_entrysource
forall K, V where Copy[K], Copy[V].
fn forget_entry(key: K, value: V) -> () { ... }
Lets a Copy key and value go: the callback destroy and clear pass to destroy_with and clear_with. Not meant for direct use.
Instance declarations
instance Iterator[Drain![K, V, 'k] -> Pair[K, V]]source
forall K, V, 'k where Sized[K], Sized[V].
instance Iterator[Drain![K, V, 'k] -> Pair[K, V]] { ... }
The drained entries, each moved out as Pair { a: key, b: value }.