Struct weak_table::PtrWeakKeyHashMap[][src]

pub struct PtrWeakKeyHashMap<K, V, S = RandomState>(_);
Expand description

A hash map with weak keys, hashed on key pointer.

When a weak pointer expires, its mapping is lazily removed.

Examples

use weak_table::PtrWeakKeyHashMap;
use std::rc::{Rc, Weak};

type Table = PtrWeakKeyHashMap<Weak<str>, usize>;

let mut map = Table::new();
let a = Rc::<str>::from("hello");
let b = Rc::<str>::from("hello");

map.insert(a.clone(), 5);

assert_eq!( map.get(&a), Some(&5) );
assert_eq!( map.get(&b), None );

map.insert(b.clone(), 7);

assert_eq!( map.get(&a), Some(&5) );
assert_eq!( map.get(&b), Some(&7) );

Implementations

Creates an empty PtrWeakKeyHashMap.

O(1) time

Creates an empty PtrWeakKeyHashMap with the given capacity.

O(n) time

Creates an empty PtrWeakKeyHashMap with the given capacity and hasher.

O(n) time

Creates an empty PtrWeakKeyHashMap with the given capacity and hasher.

O(n) time

Returns a reference to the map’s BuildHasher.

O(1) time

Returns the number of elements the map can hold without reallocating.

O(1) time

Removes all mappings whose keys have expired.

O(n) time

Reserves room for additional elements.

O(n) time

Shrinks the capacity to the minimum allowed to hold the current number of elements.

O(n) time

Returns an over-approximation of the number of elements.

O(1) time

Is the map known to be empty?

This could answer false for an empty map whose keys have expired but have yet to be collected.

O(1) time

The proportion of buckets that are used.

This is an over-approximation because of expired keys.

O(1) time

Gets the requested entry.

expected O(1) time; worst-case O(p) time

Removes all associations from the map.

O(n) time

Returns a reference to the value corresponding to the key.

expected O(1) time; worst-case O(p) time

Returns true if the map contains the specified key.

expected O(1) time; worst-case O(p) time

Returns a mutable reference to the value corresponding to the key.

expected O(1) time; worst-case O(p) time

Unconditionally inserts the value, returning the old value if already present. Does not replace the key.

expected O(1) time; worst-case O(p) time

Removes the entry with the given key, if it exists, and returns the value.

expected O(1) time; worst-case O(p) time

Removes all mappings not satisfying the given predicate.

Also removes any expired mappings.

O(n) time

Is this map a submap of the other, using the given value comparison.

In particular, all the keys of self must be in other and the values must compare true with value_equal.

expected O(n) time; worst-case O(nq) time (where n is self.capacity() and q is the length of the probe sequences in other)

Is self a submap of other?

expected O(n) time; worst-case O(nq) time (where n is self.capacity() and q is the length of the probe sequences in other)

Are the keys of self a subset of the keys of other?

expected O(n) time; worst-case O(nq) time (where n is self.capacity() and q is the length of the probe sequences in other)

Gets an iterator over the keys and values.

O(1) time

Gets an iterator over the keys.

O(1) time

Gets an iterator over the values.

O(1) time

Gets an iterator over the keys and mutable values.

O(1) time

Gets an iterator over the mutable values.

O(1) time

Gets a draining iterator, which removes all the values but retains the storage.

O(1) time (and O(n) time to dispose of the result)

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Creates a value from an iterator. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

Creates an owning iterator from self.

O(1) time (and O(n) time to dispose of the result)

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates a borrowing iterator from self.

O(1) time

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates a borrowing iterator from self.

O(1) time

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.