Struct hashlink::linked_hash_map::LinkedHashMap
source · 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
)source§impl<K: Hash + Eq, V, S: BuildHasher + Default> FromIterator<(K, V)> for LinkedHashMap<K, V, S>
impl<K: Hash + Eq, V, S: BuildHasher + Default> FromIterator<(K, V)> for LinkedHashMap<K, V, S>
source§impl<K: Hash + Eq, V: Hash, S: BuildHasher> Hash for LinkedHashMap<K, V, S>
impl<K: Hash + Eq, V: Hash, S: BuildHasher> Hash for LinkedHashMap<K, V, S>
source§impl<'a, K, V, S, Q> Index<&'a Q> for LinkedHashMap<K, V, S>
impl<'a, K, V, S, Q> Index<&'a Q> for LinkedHashMap<K, V, S>
source§impl<'a, K, V, S, Q> IndexMut<&'a Q> for LinkedHashMap<K, V, S>
impl<'a, K, V, S, Q> IndexMut<&'a Q> for LinkedHashMap<K, V, S>
source§impl<'a, K, V, S> IntoIterator for &'a LinkedHashMap<K, V, S>
impl<'a, K, V, S> IntoIterator for &'a LinkedHashMap<K, V, S>
source§impl<'a, K, V, S> IntoIterator for &'a mut LinkedHashMap<K, V, S>
impl<'a, K, V, S> IntoIterator for &'a mut LinkedHashMap<K, V, S>
source§impl<K, V, S> IntoIterator for LinkedHashMap<K, V, S>
impl<K, V, S> IntoIterator for LinkedHashMap<K, V, S>
source§impl<K: Hash + Eq + Ord, V: Ord, S: BuildHasher> Ord for LinkedHashMap<K, V, S>
impl<K: Hash + Eq + Ord, V: Ord, S: BuildHasher> Ord for LinkedHashMap<K, V, S>
source§impl<K: Hash + Eq, V: PartialEq, S: BuildHasher> PartialEq for LinkedHashMap<K, V, S>
impl<K: Hash + Eq, V: PartialEq, S: BuildHasher> PartialEq for LinkedHashMap<K, V, S>
source§impl<K: Hash + Eq + PartialOrd, V: PartialOrd, S: BuildHasher> PartialOrd for LinkedHashMap<K, V, S>
impl<K: Hash + Eq + PartialOrd, V: PartialOrd, S: BuildHasher> PartialOrd for LinkedHashMap<K, V, S>
source§fn le(&self, other: &Self) -> bool
fn le(&self, other: &Self) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl<K: Hash + Eq, V: Eq, S: BuildHasher> 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> 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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)