pub struct LinkedHashMap<K, V, S = RandomState> { /* private fields */ }Expand description
A hash map that preserves insertion order and exposes a
[VecDeque]-like API with [insert_back], [insert_front],
[pop_front], [pop_back], [front], and [back].
All the usual [HashMap] operations (get, get_mut, remove,
contains_key, len, is_empty, clear, …) are also available.
§Ordering contract
- [
insert_back] and [insert_front] preserve the position of an existing key: only the value is updated in-place. Use [move_to_back] / [move_to_front] to explicitly reorder an entry.
Implementations§
Source§impl<K, V> LinkedHashMap<K, V>
impl<K, V> LinkedHashMap<K, V>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty LinkedHashMap with the specified initial capacity.
Source§impl<K, V, S> LinkedHashMap<K, V, S>
impl<K, V, S> LinkedHashMap<K, V, S>
Sourcepub fn with_hasher(hash_builder: S) -> Self
pub fn with_hasher(hash_builder: S) -> Self
Creates an empty LinkedHashMap using the supplied hasher builder.
Sourcepub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
Creates an empty LinkedHashMap with the given capacity and hasher.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
Sourcepub fn hasher(&self) -> &S
pub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher.
Source§impl<K, V, S> LinkedHashMap<K, V, S>
impl<K, V, S> LinkedHashMap<K, V, S>
Sourcepub fn entry<'a>(&'a mut self, key: K) -> Entry<'a, K, V, S>
pub fn entry<'a>(&'a mut self, key: K) -> Entry<'a, K, V, S>
Gets the given key’s corresponding entry in the map for in-place manipulation.
Sourcepub fn insert_back(&mut self, key: K, value: V) -> Option<V>
pub fn insert_back(&mut self, key: K, value: V) -> Option<V>
Inserts a key-value pair at the back (most-recently-inserted end).
If the key already exists, the value is replaced in-place and the node’s position in the ordering is preserved (it is not moved). Returns the old value in that case.
To also move the node to the back, call move_to_back after
insertion.
Sourcepub fn insert_front(&mut self, key: K, value: V) -> Option<V>
pub fn insert_front(&mut self, key: K, value: V) -> Option<V>
Inserts a key-value pair at the front (least-recently-inserted end).
If the key already exists, the value is replaced in-place and the node’s position in the ordering is preserved (it is not moved). Returns the old value in that case.
To also move the node to the front, call move_to_front after
insertion.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Alias for insert_back: matches the HashMap::insert signature.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Returns a reference to the value associated with key, if present.
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Returns a mutable reference to the value associated with key, if
present.
Sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
Returns (&key, &value) for the given key, if present.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the map contains a value for key.
Sourcepub fn front(&self) -> Option<(&K, &V)>
pub fn front(&self) -> Option<(&K, &V)>
Returns references to the front (oldest inserted) key-value pair,
or None if the map is empty.
Sourcepub fn front_mut(&mut self) -> Option<(&K, &mut V)>
pub fn front_mut(&mut self) -> Option<(&K, &mut V)>
Returns a mutable reference to the front key-value pair, or None.
Sourcepub fn back(&self) -> Option<(&K, &V)>
pub fn back(&self) -> Option<(&K, &V)>
Returns references to the back (most recently inserted) key-value
pair, or None if the map is empty.
Sourcepub fn back_mut(&mut self) -> Option<(&K, &mut V)>
pub fn back_mut(&mut self) -> Option<(&K, &mut V)>
Returns a mutable reference to the back key-value pair, or None.
Sourcepub fn pop_front(&mut self) -> Option<(K, V)>
pub fn pop_front(&mut self) -> Option<(K, V)>
Removes and returns the front (oldest) key-value pair, or None.
Sourcepub fn pop_back(&mut self) -> Option<(K, V)>
pub fn pop_back(&mut self) -> Option<(K, V)>
Removes and returns the back (newest) key-value pair, or None.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
Removes the entry for key and returns the value, if present.
Sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Removes the entry for key and returns (key, value), if present.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only entries for which f(&key, &mut value) returns true.
Elements are visited in insertion order (front → back).
Sourcepub fn move_to_back<Q>(&mut self, key: &Q) -> bool
pub fn move_to_back<Q>(&mut self, key: &Q) -> bool
Moves the entry for key to the back of the ordering.
Returns true if the key was found, false otherwise.
Sourcepub fn move_to_front<Q>(&mut self, key: &Q) -> bool
pub fn move_to_front<Q>(&mut self, key: &Q) -> bool
Moves the entry for key to the front of the ordering.
Returns true if the key was found, false otherwise.
Source§impl<K, V, S> LinkedHashMap<K, V, S>
impl<K, V, S> LinkedHashMap<K, V, S>
Sourcepub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
Returns an iterator over (&K, &V) pairs in insertion order.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
Returns an iterator over (&K, &mut V) pairs in insertion order.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
Returns a mutable iterator over values in insertion order.
Trait Implementations§
Source§impl<K: Clone + Hash + Eq, V: Clone, S: BuildHasher + Clone> Clone for LinkedHashMap<K, V, S>
impl<K: Clone + Hash + Eq, V: Clone, S: BuildHasher + Clone> Clone for LinkedHashMap<K, V, S>
Source§impl<K, V, S> Debug for LinkedHashMap<K, V, S>
impl<K, V, S> Debug for LinkedHashMap<K, V, S>
Source§impl<K, V> Default for LinkedHashMap<K, V>
impl<K, V> Default for LinkedHashMap<K, V>
Source§impl<K, V, S> Drop for LinkedHashMap<K, V, S>
impl<K, V, S> Drop for LinkedHashMap<K, V, S>
Source§impl<K: Hash + Eq, V, S: BuildHasher> Extend<(K, V)> for LinkedHashMap<K, V, S>
impl<K: Hash + Eq, V, S: BuildHasher> Extend<(K, V)> for LinkedHashMap<K, V, S>
Source§fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<K: Hash + Eq, V> FromIterator<(K, V)> for LinkedHashMap<K, V>
impl<K: Hash + Eq, V> FromIterator<(K, V)> for LinkedHashMap<K, V>
Source§impl<K, V, S, Q> Index<&Q> for LinkedHashMap<K, V, S>
impl<K, V, S, Q> Index<&Q> for LinkedHashMap<K, V, S>
Source§impl<K, V, S, Q> IndexMut<&Q> for LinkedHashMap<K, V, S>
impl<K, V, S, Q> IndexMut<&Q> for LinkedHashMap<K, V, S>
Source§impl<'a, K, V, S> IntoIterator for &'a LinkedHashMap<K, V, S>
Shared-reference iterator: yields (&K, &V) in insertion order.
impl<'a, K, V, S> IntoIterator for &'a LinkedHashMap<K, V, S>
Shared-reference iterator: yields (&K, &V) in insertion order.
Source§impl<'a, K, V, S> IntoIterator for &'a mut LinkedHashMap<K, V, S>
Mutable-reference iterator: yields (&K, &mut V) in insertion order.
impl<'a, K, V, S> IntoIterator for &'a mut LinkedHashMap<K, V, S>
Mutable-reference iterator: yields (&K, &mut V) in insertion order.
Source§impl<K, V, S> IntoIterator for LinkedHashMap<K, V, S>
Consuming iterator: yields all (K, V) pairs in insertion order.
impl<K, V, S> IntoIterator for LinkedHashMap<K, V, S>
Consuming iterator: yields all (K, V) pairs in insertion order.
Source§impl<K, V, S1, S2> PartialEq<LinkedHashMap<K, V, S2>> for LinkedHashMap<K, V, S1>
impl<K, V, S1, S2> PartialEq<LinkedHashMap<K, V, S2>> for LinkedHashMap<K, V, S1>
Source§fn eq(&self, other: &LinkedHashMap<K, V, S2>) -> bool
fn eq(&self, other: &LinkedHashMap<K, V, S2>) -> bool
Two maps are equal only when they contain the same key-value pairs in the same order.
impl<K: PartialEq + Eq, V: Eq, S> Eq for LinkedHashMap<K, V, S>
impl<K: Send, V: Send, S: Send> Send for LinkedHashMap<K, V, S>
impl<K: Sync, V: Sync, S: Sync> Sync for LinkedHashMap<K, V, S>
Auto Trait Implementations§
impl<K, V, S> Freeze for LinkedHashMap<K, V, S>where
S: Freeze,
impl<K, V, S> RefUnwindSafe for LinkedHashMap<K, V, S>
impl<K, V, S> Unpin for LinkedHashMap<K, V, S>where
S: Unpin,
impl<K, V, S> UnsafeUnpin for LinkedHashMap<K, V, S>where
S: UnsafeUnpin,
impl<K, V, S> UnwindSafe for LinkedHashMap<K, V, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.