[][src]Struct linked_hash_map::LinkedHashMap

pub struct LinkedHashMap<K, V, S = RandomState> { /* fields omitted */ }

A linked hash map.

Methods

impl<K: Hash + Eq, V> LinkedHashMap<K, V>
[src]

Creates a linked hash map.

Creates an empty linked hash map with the given initial capacity.

impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S>
[src]

Creates an empty linked hash map with the given initial hash builder.

Creates an empty linked hash map with the given initial capacity and hash builder.

Reserves capacity for at least additional more elements to be inserted into the map. The map may reserve more space to avoid frequent allocations.

Panics

Panics if the new allocation size overflows usize.

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.

Inserts a key-value pair into the map. If the key already existed, the old value is returned.

Examples

use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();

map.insert(1, "a");
map.insert(2, "b");
assert_eq!(map[&1], "a");
assert_eq!(map[&2], "b");

Checks if the map contains the given key.

Returns the value corresponding to the key in the map.

Examples

use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();

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

assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), Some(&"c"));

Returns the mutable reference corresponding to the key in the map.

Examples

use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();

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

*map.get_mut(&1).unwrap() = "c";
assert_eq!(map.get(&1), Some(&"c"));

Returns the value corresponding to the key in the map.

If value is found, it is moved to the end of the list. This operation can be used in implemenation of LRU cache.

Examples

use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();

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

assert_eq!(map.get_refresh(&2), Some(&mut "b"));

assert_eq!((&2, &"b"), map.iter().rev().next().unwrap());

Removes and returns the value corresponding to the key from the map.

Examples

use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();

map.insert(2, "a");

assert_eq!(map.remove(&1), None);
assert_eq!(map.remove(&2), Some("a"));
assert_eq!(map.remove(&2), None);
assert_eq!(map.len(), 0);

Returns the maximum number of key-value pairs the map can hold without reallocating.

Examples

use linked_hash_map::LinkedHashMap;
let mut map: LinkedHashMap<i32, &str> = LinkedHashMap::new();
let capacity = map.capacity();

Removes the first entry.

Can be used in implementation of LRU cache.

Examples

use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(1, 10);
map.insert(2, 20);
map.pop_front();
assert_eq!(map.get(&1), None);
assert_eq!(map.get(&2), Some(&20));

Gets the first entry.

Examples

use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(1, 10);
map.insert(2, 20);
assert_eq!(map.front(), Some((&1, &10)));

Removes the last entry.

Examples

use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(1, 10);
map.insert(2, 20);
map.pop_back();
assert_eq!(map.get(&1), Some(&10));
assert_eq!(map.get(&2), None);

Gets the last entry.

Examples

use linked_hash_map::LinkedHashMap;
let mut map = LinkedHashMap::new();
map.insert(1, 10);
map.insert(2, 20);
assert_eq!(map.back(), Some((&2, &20)));

Returns the number of key-value pairs in the map.

Returns whether the map is currently empty.

Returns a reference to the map's hasher.

Clears the map of all key-value pairs.

Important traits for Iter<'a, K, V>

Returns a double-ended iterator visiting all key-value pairs in order of insertion. Iterator element type is (&'a K, &'a V)

Examples

use linked_hash_map::LinkedHashMap;

let mut map = LinkedHashMap::new();
map.insert("a", 10);
map.insert("c", 30);
map.insert("b", 20);

let mut iter = map.iter();
assert_eq!((&"a", &10), iter.next().unwrap());
assert_eq!((&"c", &30), iter.next().unwrap());
assert_eq!((&"b", &20), iter.next().unwrap());
assert_eq!(None, iter.next());

Important traits for IterMut<'a, K, V>

Returns a double-ended iterator visiting all key-value pairs in order of insertion. Iterator element type is (&'a K, &'a mut V)

Examples

use linked_hash_map::LinkedHashMap;

let mut map = LinkedHashMap::new();
map.insert("a", 10);
map.insert("c", 30);
map.insert("b", 20);

{
    let mut iter = map.iter_mut();
    let mut entry = iter.next().unwrap();
    assert_eq!(&"a", entry.0);
    *entry.1 = 17;
}

assert_eq!(&17, map.get(&"a").unwrap());

Important traits for Keys<'a, K, V>

Returns a double-ended iterator visiting all key in order of insertion.

Examples

use linked_hash_map::LinkedHashMap;

let mut map = LinkedHashMap::new();
map.insert('a', 10);
map.insert('c', 30);
map.insert('b', 20);

let mut keys = map.keys();
assert_eq!(&'a', keys.next().unwrap());
assert_eq!(&'c', keys.next().unwrap());
assert_eq!(&'b', keys.next().unwrap());
assert_eq!(None, keys.next());

Important traits for Values<'a, K, V>

Returns a double-ended iterator visiting all values in order of insertion.

Examples

use linked_hash_map::LinkedHashMap;

let mut map = LinkedHashMap::new();
map.insert('a', 10);
map.insert('c', 30);
map.insert('b', 20);

let mut values = map.values();
assert_eq!(&10, values.next().unwrap());
assert_eq!(&30, values.next().unwrap());
assert_eq!(&20, values.next().unwrap());
assert_eq!(None, values.next());

Trait Implementations

impl<'a, K: Hash + Eq, V, S: BuildHasher> IntoIterator for &'a LinkedHashMap<K, V, S>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Important traits for Iter<'a, K, V>

Creates an iterator from a value. Read more

impl<'a, K: Hash + Eq, V, S: BuildHasher> IntoIterator for &'a mut LinkedHashMap<K, V, S>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Important traits for IterMut<'a, K, V>

Creates an iterator from a value. Read more

impl<K: Hash + Eq, V, S: BuildHasher> IntoIterator for LinkedHashMap<K, V, S>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Important traits for IntoIter<K, V>

Creates an iterator from a value. Read more

impl<K: Send, V: Send, S: Send> Send for LinkedHashMap<K, V, S>
[src]

impl<K: Hash + Eq + Ord, V: Ord, S: BuildHasher> Ord for LinkedHashMap<K, V, S>
[src]

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl<K, V, S> Drop for LinkedHashMap<K, V, S>
[src]

Executes the destructor for this type. Read more

impl<K: Hash + Eq + Clone, V: Clone, S: BuildHasher + Clone> Clone for LinkedHashMap<K, V, S>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<K: Hash + Eq, V, S: BuildHasher> Extend<(K, V)> for LinkedHashMap<K, V, S>
[src]

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

impl<'a, K, V, S> Extend<(&'a K, &'a V)> for LinkedHashMap<K, V, S> where
    K: 'a + Hash + Eq + Copy,
    V: 'a + Copy,
    S: BuildHasher
[src]

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

impl<K: Hash + Eq + PartialOrd, V: PartialOrd, S: BuildHasher> PartialOrd<LinkedHashMap<K, V, S>> for LinkedHashMap<K, V, S>
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

impl<K: Hash + Eq, V: Eq, S: BuildHasher> Eq for LinkedHashMap<K, V, S>
[src]

impl<K: Sync, V: Sync, S: Sync> Sync for LinkedHashMap<K, V, S>
[src]

impl<K: Hash + Eq, V, S: BuildHasher + Default> Default for LinkedHashMap<K, V, S>
[src]

Returns the "default value" for a type. Read more

impl<K: Hash + Eq, V: PartialEq, S: BuildHasher> PartialEq<LinkedHashMap<K, V, S>> for LinkedHashMap<K, V, S>
[src]

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

This method tests for !=.

impl<K: Hash + Eq, V: Hash, S: BuildHasher> Hash for LinkedHashMap<K, V, S>
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl<A: Debug + Hash + Eq, B: Debug, S: BuildHasher> Debug for LinkedHashMap<A, B, S>
[src]

Returns a string that lists the key-value pairs in insertion order.

impl<'a, K, V, S, Q: ?Sized> Index<&'a Q> for LinkedHashMap<K, V, S> where
    K: Hash + Eq + Borrow<Q>,
    S: BuildHasher,
    Q: Eq + Hash
[src]

The returned type after indexing.

Performs the indexing (container[index]) operation.

impl<'a, K, V, S, Q: ?Sized> IndexMut<&'a Q> for LinkedHashMap<K, V, S> where
    K: Hash + Eq + Borrow<Q>,
    S: BuildHasher,
    Q: Eq + Hash
[src]

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

impl<K: Hash + Eq, V, S: BuildHasher + Default> FromIterator<(K, V)> for LinkedHashMap<K, V, S>
[src]

Creates a value from an iterator. Read more

impl<K, V> Deserialize for LinkedHashMap<K, V> where
    K: Deserialize + Eq + Hash,
    V: Deserialize
[src]

Deserialize this value given this Deserializer.

impl<K, V, S> Serialize for LinkedHashMap<K, V, S> where
    K: Serialize + Eq + Hash,
    V: Serialize,
    S: BuildHasher
[src]

Serializes this value into this serializer.

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

impl<I> IntoIterator for I where
    I: Iterator
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

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

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

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

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

recently added

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

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

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

Immutably borrows from an owned value. Read more

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

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

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

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

Mutably borrows from an owned value. Read more

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

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

The type returned in the event of a conversion error.

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

Performs the conversion.