pub struct LinkedHashMap<K, V, S = DefaultHashBuilder> { /* private fields */ }
Expand description
A version of HashMap
that has a user controllable order for its entries.
It achieves this by keeping its entries in an internal linked list and using a HashMap
to
point at nodes in this linked list.
The order of entries defaults to “insertion order”, but the user can also modify the order of existing entries by manually moving them to the front or back.
There are two kinds of methods that modify the order of the internal list:
- Methods that have names like
to_front
andto_back
will unsurprisingly move an existing entry to the front or back - Methods that have the word
insert
will insert a new entry ot the back of the list, and if that method might replace an entry, that method will also move that existing entry to the back.
Implementations§
Source§impl<K, V> LinkedHashMap<K, V>
impl<K, V> LinkedHashMap<K, V>
pub fn new() -> Self
pub fn with_capacity(capacity: usize) -> Self
Source§impl<K, V, S> LinkedHashMap<K, V, S>
impl<K, V, S> LinkedHashMap<K, V, S>
pub fn with_hasher(hash_builder: S) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn clear(&mut self)
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn drain(&mut self) -> Drain<'_, K, V> ⓘ
pub fn keys(&self) -> Keys<'_, K, V> ⓘ
pub fn values(&self) -> Values<'_, K, V> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
pub fn front(&self) -> Option<(&K, &V)>
pub fn back(&self) -> Option<(&K, &V)>
pub fn retain<F>(&mut self, f: F)
pub fn hasher(&self) -> &S
pub fn capacity(&self) -> usize
Source§impl<K, V, S> LinkedHashMap<K, V, S>
impl<K, V, S> LinkedHashMap<K, V, S>
pub fn entry(&mut self, key: K) -> Entry<'_, K, V, S>
pub fn get<Q>(&self, k: &Q) -> Option<&V>
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
pub fn contains_key<Q>(&self, k: &Q) -> bool
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
pub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts the given key / value pair at the back of the internal linked list.
Returns the previously set value, if one existed prior to this call. After this call,
calling LinkedHashMap::back
will return a reference to this key / value pair.
Sourcepub fn replace(&mut self, k: K, v: V) -> Option<V>
pub fn replace(&mut self, k: K, v: V) -> Option<V>
If the given key is not in this map, inserts the key / value pair at the back of the
internal linked list and returns None
, otherwise, replaces the existing value with the
given value without moving the entry in the internal linked list and returns the previous
value.
pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
pub fn pop_front(&mut self) -> Option<(K, V)>
pub fn pop_back(&mut self) -> Option<(K, V)>
Sourcepub fn to_front<Q>(&mut self, k: &Q) -> Option<&mut V>
pub fn to_front<Q>(&mut self, k: &Q) -> Option<&mut V>
If an entry with this key exists, move it to the front of the list and return a reference to the value.
Sourcepub fn to_back<Q>(&mut self, k: &Q) -> Option<&mut V>
pub fn to_back<Q>(&mut self, k: &Q) -> Option<&mut V>
If an entry with this key exists, move it to the back of the list and return a reference to the value.
pub fn reserve(&mut self, additional: usize)
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn shrink_to_fit(&mut self)
pub fn retain_with_order<F>(&mut self, f: F)
Sourcepub fn cursor_front_mut(&mut self) -> CursorMut<'_, K, V, S>
pub fn cursor_front_mut(&mut self) -> CursorMut<'_, K, V, S>
Returns the CursorMut
over the front node.
Note: The CursorMut
is pointing to the guard node in an empty LinkedHashMap
and
will always return None
as its current element, regardless of any move in any
direction.
Sourcepub fn cursor_back_mut(&mut self) -> CursorMut<'_, K, V, S>
pub fn cursor_back_mut(&mut self) -> CursorMut<'_, K, V, S>
Returns the CursorMut
over the back node.
Note: The CursorMut
is pointing to the guard node in an empty LinkedHashMap
and
will always return None
as its current element, regardless of any move in any
direction.
Source§impl<K, V, S> LinkedHashMap<K, V, S>where
S: BuildHasher,
impl<K, V, S> LinkedHashMap<K, V, S>where
S: BuildHasher,
pub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
pub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
Trait Implementations§
Source§impl<K: Hash + Eq + Clone, V: Clone, S: BuildHasher + Clone> Clone for LinkedHashMap<K, V, S>
impl<K: Hash + Eq + Clone, 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, S> Default for LinkedHashMap<K, V, S>where
S: Default,
impl<K, V, S> Default for LinkedHashMap<K, V, S>where
S: Default,
Source§impl<K, V, S> Drop for LinkedHashMap<K, V, S>
impl<K, V, S> Drop for LinkedHashMap<K, V, S>
Source§impl<'a, K, V, S> Extend<(&'a K, &'a V)> for LinkedHashMap<K, V, S>
impl<'a, K, V, S> Extend<(&'a K, &'a V)> for LinkedHashMap<K, V, S>
Source§fn extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (&'a K, &'a 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, 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
)