hashlink::linked_hash_map

Struct 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 and to_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>

Source

pub fn new() -> Self

Source

pub fn with_capacity(capacity: usize) -> Self

Source§

impl<K, V, S> LinkedHashMap<K, V, S>

Source

pub fn with_hasher(hash_builder: S) -> Self

Source

pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn clear(&mut self)

Source

pub fn iter(&self) -> Iter<'_, K, V>

Source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

Source

pub fn drain(&mut self) -> Drain<'_, K, V>

Source

pub fn keys(&self) -> Keys<'_, K, V>

Source

pub fn values(&self) -> Values<'_, K, V>

Source

pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>

Source

pub fn front(&self) -> Option<(&K, &V)>

Source

pub fn back(&self) -> Option<(&K, &V)>

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&K, &mut V) -> bool,

Source

pub fn hasher(&self) -> &S

Source

pub fn capacity(&self) -> usize

Source§

impl<K, V, S> LinkedHashMap<K, V, S>
where K: Eq + Hash, S: BuildHasher,

Source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V, S>

Source

pub fn get<Q>(&self, k: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Source

pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Source

pub fn contains_key<Q>(&self, k: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Source

pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Source

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.

Source

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.

Source

pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Source

pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Source

pub fn pop_front(&mut self) -> Option<(K, V)>

Source

pub fn pop_back(&mut self) -> Option<(K, V)>

Source

pub fn to_front<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

If an entry with this key exists, move it to the front of the list and return a reference to the value.

Source

pub fn to_back<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

If an entry with this key exists, move it to the back of the list and return a reference to the value.

Source

pub fn reserve(&mut self, additional: usize)

Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

Source

pub fn shrink_to_fit(&mut self)

Source

pub fn retain_with_order<F>(&mut self, f: F)
where F: FnMut(&K, &mut V) -> bool,

Source

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.

Source

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,

Source

pub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>

Source

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>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V, S> Debug for LinkedHashMap<K, V, S>
where K: Debug, V: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V, S> Default for LinkedHashMap<K, V, S>
where S: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K, V, S> Drop for LinkedHashMap<K, V, S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

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,

Source§

fn extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: I)

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

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

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)

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

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

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

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

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

Source§

fn hash<H: Hasher>(&self, h: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

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

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, index: &'a Q) -> &V

Performs the indexing (container[index]) operation. Read more
Source§

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

Source§

fn index_mut(&mut self, index: &'a Q) -> &mut V

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, K, V, S> IntoIterator for &'a LinkedHashMap<K, V, S>

Source§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Iter<'a, K, V>

Creates an iterator from a value. Read more
Source§

impl<'a, K, V, S> IntoIterator for &'a mut LinkedHashMap<K, V, S>

Source§

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IterMut<'a, K, V>

Creates an iterator from a value. Read more
Source§

impl<K, V, S> IntoIterator for LinkedHashMap<K, V, S>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IntoIter<K, V>

Creates an iterator from a value. Read more
Source§

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

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

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

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

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

fn lt(&self, other: &Self) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
Source§

fn le(&self, other: &Self) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

fn ge(&self, other: &Self) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

fn gt(&self, other: &Self) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

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

Source§

impl<K: Send, V: Send, S: Send> Send for LinkedHashMap<K, V, S>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.