Struct transient_hashmap::TransientHashMap [] [src]

pub struct TransientHashMap<K, V, T = StandardTimer> where
    T: Timer
{ /* fields omitted */ }

HashMap with entries that will be garbage collected (pruned) after not being used for specified time.

Pruning does not occur automatically, make sure to call prune method to remove old entries.

Methods

impl<K, V> TransientHashMap<K, V, StandardTimer> where
    K: Eq + Hash + Clone
[src]

[src]

Creates new TransientHashMap with standard timer and specified entries lifetime.

impl<K, V, T> TransientHashMap<K, V, T> where
    K: Eq + Hash + Clone,
    T: Timer
[src]

[src]

Creates new TransientHashMap with given timer and specfied entries lifetime.

[src]

Insert new entry to this map overwriting any previous entry.

Prolongs lifetime of key.

[src]

Insert new entry to this map overwriting any previous entry.

Always prolongs the lifetime of key. TODO [ToDr] Should only prolong if new item is inserted or entry is occupied.

[src]

Gets reference to stored value.

Prolongs lifetime of key if is in the map.

[src]

Gets mutable reference to stored value.

Prolongs lifetime of key if is in the map.

[src]

Checks if key is contained.

Prolongs lifetime of key if is in the map.

[src]

Removes key from the map if present.

Also removes associated lifetime.

[src]

Returns remaining lifetime of key without altering it.

Important traits for Vec<u8>
[src]

Clear overdue entries from the TransientHashMap.

[src]

Get a reference to backing HashMap.

[src]

Get the mutable reference to backing HashMap.

Methods from Deref<Target = HashMap<K, V>>

Important traits for &'a mut W
1.9.0
[src]

Returns a reference to the map's BuildHasher.

Examples

use std::collections::HashMap;
use std::collections::hash_map::RandomState;

let hasher = RandomState::new();
let map: HashMap<isize, isize> = HashMap::with_hasher(hasher);
let hasher: &RandomState = map.hasher();

1.0.0
[src]

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

This number is a lower bound; the HashMap<K, V> might be able to hold more, but is guaranteed to be able to hold at least this many.

Examples

use std::collections::HashMap;
let map: HashMap<isize, isize> = HashMap::with_capacity(100);
assert!(map.capacity() >= 100);

1.0.0
[src]

Reserves capacity for at least additional more elements to be inserted in the HashMap. The collection may reserve more space to avoid frequent reallocations.

Panics

Panics if the new allocation size overflows usize.

Examples

use std::collections::HashMap;
let mut map: HashMap<&str, isize> = HashMap::new();
map.reserve(10);

1.0.0
[src]

Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.

Examples

use std::collections::HashMap;

let mut map: HashMap<isize, isize> = HashMap::with_capacity(100);
map.insert(1, 2);
map.insert(3, 4);
assert!(map.capacity() >= 100);
map.shrink_to_fit();
assert!(map.capacity() >= 2);

Important traits for Keys<'a, K, V>
1.0.0
[src]

An iterator visiting all keys in arbitrary order. The iterator element type is &'a K.

Examples

use std::collections::HashMap;

let mut map = HashMap::new();
map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

for key in map.keys() {
    println!("{}", key);
}

Important traits for Values<'a, K, V>
1.0.0
[src]

An iterator visiting all values in arbitrary order. The iterator element type is &'a V.

Examples

use std::collections::HashMap;

let mut map = HashMap::new();
map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

for val in map.values() {
    println!("{}", val);
}

Important traits for ValuesMut<'a, K, V>
1.10.0
[src]

An iterator visiting all values mutably in arbitrary order. The iterator element type is &'a mut V.

Examples

use std::collections::HashMap;

let mut map = HashMap::new();

map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

for val in map.values_mut() {
    *val = *val + 10;
}

for val in map.values() {
    println!("{}", val);
}

Important traits for Iter<'a, K, V>
1.0.0
[src]

An iterator visiting all key-value pairs in arbitrary order. The iterator element type is (&'a K, &'a V).

Examples

use std::collections::HashMap;

let mut map = HashMap::new();
map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

for (key, val) in map.iter() {
    println!("key: {} val: {}", key, val);
}

Important traits for IterMut<'a, K, V>
1.0.0
[src]

An iterator visiting all key-value pairs in arbitrary order, with mutable references to the values. The iterator element type is (&'a K, &'a mut V).

Examples

use std::collections::HashMap;

let mut map = HashMap::new();
map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);

// Update all values
for (_, val) in map.iter_mut() {
    *val *= 2;
}

for (key, val) in &map {
    println!("key: {} val: {}", key, val);
}

1.0.0
[src]

Gets the given key's corresponding entry in the map for in-place manipulation.

Examples

use std::collections::HashMap;

let mut letters = HashMap::new();

for ch in "a short treatise on fungi".chars() {
    let counter = letters.entry(ch).or_insert(0);
    *counter += 1;
}

assert_eq!(letters[&'s'], 2);
assert_eq!(letters[&'t'], 3);
assert_eq!(letters[&'u'], 1);
assert_eq!(letters.get(&'y'), None);

1.0.0
[src]

Returns the number of elements in the map.

Examples

use std::collections::HashMap;

let mut a = HashMap::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);

1.0.0
[src]

Returns true if the map contains no elements.

Examples

use std::collections::HashMap;

let mut a = HashMap::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());

Important traits for Drain<'a, K, V>
1.6.0
[src]

Clears the map, returning all key-value pairs as an iterator. Keeps the allocated memory for reuse.

Examples

use std::collections::HashMap;

let mut a = HashMap::new();
a.insert(1, "a");
a.insert(2, "b");

for (k, v) in a.drain().take(1) {
    assert!(k == 1 || k == 2);
    assert!(v == "a" || v == "b");
}

assert!(a.is_empty());

1.0.0
[src]

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

Examples

use std::collections::HashMap;

let mut a = HashMap::new();
a.insert(1, "a");
a.clear();
assert!(a.is_empty());

1.0.0
[src]

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map's key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples

use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);

1.0.0
[src]

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the map's key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples

use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);

1.0.0
[src]

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

The key may be any borrowed form of the map's key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples

use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(1, "a");
if let Some(x) = map.get_mut(&1) {
    *x = "b";
}
assert_eq!(map[&1], "b");

1.0.0
[src]

Inserts a key-value pair into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be == without being identical. See the module-level documentation for more.

Examples

use std::collections::HashMap;

let mut map = HashMap::new();
assert_eq!(map.insert(37, "a"), None);
assert_eq!(map.is_empty(), false);

map.insert(37, "b");
assert_eq!(map.insert(37, "c"), Some("b"));
assert_eq!(map[&37], "c");

1.0.0
[src]

Removes a key from the map, returning the value at the key if the key was previously in the map.

The key may be any borrowed form of the map's key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples

use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.remove(&1), Some("a"));
assert_eq!(map.remove(&1), None);

[src]

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

Removes a key from the map, returning the stored key and value if the key was previously in the map.

The key may be any borrowed form of the map's key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples

#![feature(hash_map_remove_entry)]
use std::collections::HashMap;

let mut map = HashMap::new();
map.insert(1, "a");
assert_eq!(map.remove_entry(&1), Some((1, "a")));
assert_eq!(map.remove(&1), None);

1.18.0
[src]

Retains only the elements specified by the predicate.

In other words, remove all pairs (k, v) such that f(&k,&mut v) returns false.

Examples

use std::collections::HashMap;

let mut map: HashMap<isize, isize> = (0..8).map(|x|(x, x*10)).collect();
map.retain(|&k, _| k % 2 == 0);
assert_eq!(map.len(), 4);

Trait Implementations

impl<K, V, T> Deref for TransientHashMap<K, V, T> where
    T: Timer
[src]

The resulting type after dereferencing.

[src]

Dereferences the value.

impl<K, V, T> DerefMut for TransientHashMap<K, V, T> where
    T: Timer
[src]

[src]

Mutably dereferences the value.

Auto Trait Implementations

impl<K, V, T> Send for TransientHashMap<K, V, T> where
    K: Send,
    T: Send,
    V: Send

impl<K, V, T> Sync for TransientHashMap<K, V, T> where
    K: Sync,
    T: Sync,
    V: Sync