[][src]Struct trashmap::TrashMap

pub struct TrashMap<K: ?Sized, V, S = RandomState> { /* fields omitted */ }

A hash map that can operate on known hash values (Trash) instead of actual keys

Sometimes you need to access the same element in the hashmap multiple times and don't wish to re-hash each time. In such a case, you can use TrashMap, which will provide a Trash id that can be used to cheaply access map values as long as you keep it around.

An assumption made here is that there are no hash collisions in the u64 hash space for your hasher. If there are, this may result in unpredictable behavior.

use trashmap::TrashMap;

let mut map = TrashMap::new();
let id = map.insert("foo", "bar");
do_stuff(&mut map);
assert!(map.get(id) == Some(&"bar"));
map.remove(id);

Methods

impl<K: ?Sized, V, S> TrashMap<K, V, S> where
    K: Eq + Hash,
    S: BuildHasher
[src]

pub fn new() -> Self where
    S: Default
[src]

Construct a basic TrashMap

pub fn with_capacity_and_hasher(cap: usize, hasher: S) -> Self[src]

Construct a TrashMap with a custom hasher and/or capacity

pub fn insert<Q: ?Sized>(&mut self, k: &Q, v: V) -> Trash where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Inserts a key-value pair, returning the Trash id for the entry

pub fn insert_id(&mut self, k: Trash, v: V) -> Option<V>[src]

Inserts a key-value pair, using the Trash id for the key

Returns the old value if present

pub fn insert_replace<Q: ?Sized>(&mut self, k: &Q, v: V) -> (Trash, Option<V>) where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Inserts a key-value pair, returning the Trash id for the entry as well as the old entry, if present

pub fn get(&self, key: Trash) -> Option<&V>[src]

Gets the entry corresponding to a given Trash id, if present

pub fn get_key<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Gets the entry corresponding to a given key, if present.

pub fn remove(&mut self, key: Trash) -> Option<V>[src]

Removes and returns the entry corresponding to a given Trash id, if present

pub fn remove_key<Q: ?Sized>(&mut self, key: &Q) -> Option<V> where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Removes and returns an entry corresponding to a given key

pub fn trash<Q: ?Sized>(&self, k: &Q) -> Trash where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Get the Trash id for a given key

Trait Implementations

impl<K: ?Sized, V, S> Default for TrashMap<K, V, S> where
    K: Eq + Hash,
    S: BuildHasher + Default
[src]

Auto Trait Implementations

impl<K, V, S = RandomState> !Send for TrashMap<K, V, S>

impl<K, V, S = RandomState> !Sync for TrashMap<K, V, S>

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]