Struct KeyNodeList

Source
pub struct KeyNodeList<K, N, M = HashMap<K, N>> { /* private fields */ }
Expand description

A doubly-linked list that stores key-node pairs.

Implementations§

Source§

impl<K, N, M> KeyNodeList<K, N, M>
where M: Default,

Source

pub fn new() -> Self

Creates an empty linked list.

Source§

impl<K, N, M> KeyNodeList<K, N, M>
where M: Map<K, N>,

Source

pub fn with_map(map: M) -> Self

Creates an linked list with the given hash map map.

Source

pub fn front_key(&self) -> Option<&K>

Returns a reference to the front key, or None if the list is empty.

This operation should compute in O(1) time.

Source

pub fn back_key(&self) -> Option<&K>

Returns a reference to the back key, or None if the list is empty.

This operation should compute in O(1) time.

Source

pub fn len(&self) -> usize

Returns the number of key-node pairs in the list.

This operation should compute in O(1) time.

Source

pub fn is_empty(&self) -> bool

Returns true if the list contains no key-node pairs.

This operation should compute in O(1) time.

Source

pub fn clear(&mut self)

Removes all key-node pairs in the list.

Source

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

Returns an iterator over all keys and nodes. The iterator element type is (&'a K, &'a N).

Source

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

Returns an iterator over all keys. The iterator element type is &'a K.

Source

pub fn nodes(&self) -> Nodes<'_, K, N, M>

Returns an iterator over all nodes. The iterator element type is &'a N.

Source§

impl<K, N, M> KeyNodeList<K, N, M>
where K: Hash + Eq, M: Map<K, N>,

Source

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

Returns true if the linked list contains a node for the specified key.

This operation should compute in O(1) time on average.

Source

pub fn node<Q>(&self, key: &Q) -> Option<&N>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a reference to the node corresponding to the key, or None if key does not exist.

This operation should compute in O(1) time on average.

Source

pub fn node_mut<Q>(&mut self, key: &Q) -> Option<&mut N>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a mutable reference to the node corresponding to the key, or None if key does not exist.

This operation should compute in O(1) time on average.

Source

pub fn front_node(&self) -> Option<&N>

Returns a reference to the front node, or None if the list is empty.

This operation should compute in O(1) time on average.

Source

pub fn front_node_mut(&mut self) -> Option<&mut N>

Returns a mutable reference to the front node, or None if the list is empty.

This operation should compute in O(1) time on average.

Source

pub fn back_node(&self) -> Option<&N>

Returns a reference to the back node, or None if the list is empty.

This operation should compute in O(1) time on average.

Source

pub fn back_node_mut(&mut self) -> Option<&mut N>

Returns a mutable reference to the back node, or None if the list is empty.

This operation should compute in O(1) time on average.

Source

pub fn cursor(&self, key: K) -> Cursor<'_, K, N, M>

Provides a cursor at the specific key.

The cursor is pointing to the null pair if the key does not exist.

Source

pub fn cursor_mut(&mut self, key: K) -> CursorMut<'_, K, N, M>

Provides a cursor with editing operations at the specific key.

The cursor is pointing to the null pair if the key does not exist.

Source§

impl<K, N, M> KeyNodeList<K, N, M>
where K: Hash + Eq + Clone, M: Map<K, N>,

Source

pub fn cursor_front(&self) -> Cursor<'_, K, N, M>

Provides a cursor at the front key-node pair.

The cursor is pointing to the null pair if the list is empty.

Source

pub fn cursor_front_mut(&mut self) -> CursorMut<'_, K, N, M>

Provides a cursor with editing operations at the front key-node pair.

The cursor is pointing to the null pair if the list is empty.

Source

pub fn cursor_back(&self) -> Cursor<'_, K, N, M>

Provides a cursor at the back key-node pair.

The cursor is pointing to the null pair if the list is empty.

Source

pub fn cursor_back_mut(&mut self) -> CursorMut<'_, K, N, M>

Provides a cursor with editing operations at the back key-node pair.

The cursor is pointing to the null pair if the list is empty.

Source§

impl<K, N, M> KeyNodeList<K, N, M>
where K: Hash + Eq + Clone, N: Node<Key = K>, M: Map<K, N>,

Source

pub fn into_keys(self) -> IntoKeys<K, N, M>

Creates a consuming iterator over all keys. The list cannot be used after calling this. The iterator element type is K.

Source

pub fn into_nodes(self) -> IntoNodes<K, N, M>

Creates a consuming iterator over all nodes. The list cannot be used after calling this. The iterator element type is N.

Source

pub fn push_front<T: Into<N>>(&mut self, key: K, node: T) -> Result<(), (K, T)>

Adds a key-node pair first in the list.

If key already exists, returns an error containing key and node.

This operation should compute in O(1) time on average.

Source

pub fn push_back<T: Into<N>>(&mut self, key: K, node: T) -> Result<(), (K, T)>

Adds a key-node pair back in the list.

If key already exists, returns an error containing key and node.

This operation should compute in O(1) time on average.

Source

pub fn push_key_front(&mut self, key: K) -> Result<(), K>
where (): Into<N>,

Adds a key first in the list.

If key already exists, returns an error containing key.

This operation should compute in O(1) time on average.

Source

pub fn push_key_back(&mut self, key: K) -> Result<(), K>
where (): Into<N>,

Adds a key back in the list.

If key already exists, returns an error containing key.

This operation should compute in O(1) time on average.

Source

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

Removes the first key-node pair and returns it, or None if the list is empty.

This operation should compute in O(1) time on average.

Source

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

Removes the last key-node pair and returns it, or None if the list is empty.

This operation should compute in O(1) time on average.

Source

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

Removes the key-node pair at the given key and returns it, or returns None if key does not exists.

Trait Implementations§

Source§

impl<K: Clone, N: Clone, M: Clone> Clone for KeyNodeList<K, N, M>

Source§

fn clone(&self) -> KeyNodeList<K, N, M>

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

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

Performs copy-assignment from source. Read more
Source§

impl<K, N, M> Debug for KeyNodeList<K, N, M>
where K: Hash + Eq + Debug, N: Node<Key = K> + Debug, M: Map<K, N>,

Source§

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

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

impl<K, N, M> Default for KeyNodeList<K, N, M>
where M: Default,

Source§

fn default() -> Self

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

impl<'a, K, N, M> Extend<&'a K> for KeyNodeList<K, N, M>
where K: Eq + Hash + Copy + 'a, (): Into<N>, N: Node<Key = K> + Copy, M: Map<K, N>,

Source§

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

Extends a KeyNodeList with an key iterator if the node can be built with a ().

§Example
use key_node_list::KeyValueList;

let mut list: KeyValueList<i32, ()> = KeyValueList::new();
list.extend(&[1, 2, 3]);
assert_eq!(list.front_key(), Some(&1));
assert_eq!(list.back_key(), Some(&3));
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<'a, K, T, N, M> Extend<(&'a K, &'a T)> for KeyNodeList<K, N, M>
where K: Eq + Hash + Copy, T: Into<N> + Copy, N: Node<Key = K> + Copy, M: Map<K, N>,

Source§

fn extend<I: IntoIterator<Item = (&'a K, &'a T)>>(&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, T, N, M> Extend<(K, T)> for KeyNodeList<K, N, M>
where K: Eq + Hash + Clone, T: Into<N>, N: Node<Key = K>, M: Map<K, N>,

Source§

fn extend<I: IntoIterator<Item = (K, T)>>(&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, N, M> Extend<K> for KeyNodeList<K, N, M>
where K: Eq + Hash + Clone, (): Into<N>, N: Node<Key = K>, M: Map<K, N>,

Source§

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

Extends a KeyNodeList with an key iterator if the node can be built with a ().

§Example
use key_node_list::KeyValueList;

let mut list: KeyValueList<i32, ()> = KeyValueList::new();
list.extend([1, 2, 3]);
assert_eq!(list.front_key(), Some(&1));
assert_eq!(list.back_key(), Some(&3));
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, T, N, M, const LEN: usize> From<[(K, T); LEN]> for KeyNodeList<K, N, M>
where K: Eq + Hash + Clone, T: Into<N>, N: Node<Key = K>, M: Map<K, N> + Default,

Source§

fn from(arr: [(K, T); LEN]) -> Self

Converts to this type from the input type.
Source§

impl<K, T, N, M> FromIterator<(K, T)> for KeyNodeList<K, N, M>
where K: Eq + Hash + Clone, T: Into<N>, N: Node<Key = K>, M: Map<K, N> + Default,

Source§

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

Creates a value from an iterator. Read more
Source§

impl<K, N, M> FromIterator<K> for KeyNodeList<K, N, M>
where K: Eq + Hash + Clone, (): Into<N>, N: Node<Key = K>, M: Map<K, N> + Default,

Source§

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

Creates a KeyNodeList from an key iterator if the node can be built with a ().

§Example
use key_node_list::KeyValueList;

let list: KeyValueList<i32, ()> = [1, 2, 3].into_iter().collect();
assert_eq!(list.front_key(), Some(&1));
assert_eq!(list.back_key(), Some(&3));
Source§

impl<'a, K, Q, N, M> Index<&'a Q> for KeyNodeList<K, N, M>
where K: Hash + Eq + Borrow<Q>, Q: ?Sized + Hash + Eq, M: Map<K, N>,

Source§

fn index(&self, key: &'a Q) -> &Self::Output

Returns a reference to the value corresponding to the supplied key.

§Panics

Panics if the key is not present in the KeyNodeList.

Source§

type Output = N

The returned type after indexing.
Source§

impl<'a, K, N, M> IntoIterator for &'a KeyNodeList<K, N, M>
where K: Hash + Eq, N: Node<Key = K>, M: Map<K, N>,

Source§

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

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, N, M>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K, N, M> IntoIterator for KeyNodeList<K, N, M>
where K: Hash + Eq + Clone, N: Node<Key = K>, M: Map<K, N>,

Source§

type Item = (K, N)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, N, M>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K, N, M> PartialEq for KeyNodeList<K, N, M>
where M: PartialEq,

Source§

fn eq(&self, other: &KeyNodeList<K, N, M>) -> bool

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

const 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, N, M> Eq for KeyNodeList<K, N, M>
where M: PartialEq,

Auto Trait Implementations§

§

impl<K, N, M> Freeze for KeyNodeList<K, N, M>
where M: Freeze, K: Freeze,

§

impl<K, N, M> RefUnwindSafe for KeyNodeList<K, N, M>

§

impl<K, N, M> Send for KeyNodeList<K, N, M>
where M: Send, K: Send, N: Send,

§

impl<K, N, M> Sync for KeyNodeList<K, N, M>
where M: Sync, K: Sync, N: Sync,

§

impl<K, N, M> Unpin for KeyNodeList<K, N, M>
where M: Unpin, K: Unpin, N: Unpin,

§

impl<K, N, M> UnwindSafe for KeyNodeList<K, N, M>
where M: UnwindSafe, K: UnwindSafe, N: UnwindSafe,

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.