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,
impl<K, N, M> KeyNodeList<K, N, M>where
M: Default,
Source§impl<K, N, M> KeyNodeList<K, N, M>where
M: Map<K, N>,
impl<K, N, M> KeyNodeList<K, N, M>where
M: Map<K, N>,
Sourcepub fn front_key(&self) -> Option<&K>
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.
Sourcepub fn back_key(&self) -> Option<&K>
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.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of key-node pairs in the list.
This operation should compute in O(1) time.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the list contains no key-node pairs.
This operation should compute in O(1) time.
Sourcepub fn iter(&self) -> Iter<'_, K, N, M> ⓘ
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§impl<K, N, M> KeyNodeList<K, N, M>
impl<K, N, M> KeyNodeList<K, N, M>
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true
if the linked list contains a node for the specified key.
This operation should compute in O(1) time on average.
Sourcepub fn node<Q>(&self, key: &Q) -> Option<&N>
pub fn node<Q>(&self, key: &Q) -> Option<&N>
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.
Sourcepub fn node_mut<Q>(&mut self, key: &Q) -> Option<&mut N>
pub fn node_mut<Q>(&mut self, key: &Q) -> Option<&mut N>
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.
Sourcepub fn front_node(&self) -> Option<&N>
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.
Sourcepub fn front_node_mut(&mut self) -> Option<&mut N>
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.
Sourcepub fn back_node(&self) -> Option<&N>
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.
Sourcepub fn back_node_mut(&mut self) -> Option<&mut N>
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.
Sourcepub fn cursor(&self, key: K) -> Cursor<'_, K, N, M>
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.
Sourcepub fn cursor_mut(&mut self, key: K) -> CursorMut<'_, K, N, M>
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>
impl<K, N, M> KeyNodeList<K, N, M>
Sourcepub fn cursor_front(&self) -> Cursor<'_, K, N, M>
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.
Sourcepub fn cursor_front_mut(&mut self) -> CursorMut<'_, K, N, M>
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.
Sourcepub fn cursor_back(&self) -> Cursor<'_, K, N, M>
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.
Sourcepub fn cursor_back_mut(&mut self) -> CursorMut<'_, K, N, M>
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>
impl<K, N, M> KeyNodeList<K, N, M>
Sourcepub fn into_keys(self) -> IntoKeys<K, N, M> ⓘ
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
.
Sourcepub fn into_nodes(self) -> IntoNodes<K, N, M> ⓘ
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
.
Sourcepub fn push_front<T: Into<N>>(&mut self, key: K, node: T) -> Result<(), (K, T)>
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.
Sourcepub fn push_back<T: Into<N>>(&mut self, key: K, node: T) -> Result<(), (K, T)>
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.
Sourcepub fn push_key_front(&mut self, key: K) -> Result<(), K>
pub fn push_key_front(&mut self, key: K) -> Result<(), K>
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.
Sourcepub fn push_key_back(&mut self, key: K) -> Result<(), K>
pub fn push_key_back(&mut self, key: K) -> Result<(), K>
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.
Sourcepub fn pop_front(&mut self) -> Option<(K, N)>
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.
Trait Implementations§
Source§impl<K: Clone, N: Clone, M: Clone> Clone for KeyNodeList<K, N, M>
impl<K: Clone, N: Clone, M: Clone> Clone for KeyNodeList<K, N, M>
Source§fn clone(&self) -> KeyNodeList<K, N, M>
fn clone(&self) -> KeyNodeList<K, N, M>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<K, N, M> Debug for KeyNodeList<K, N, M>
impl<K, N, M> Debug for KeyNodeList<K, N, M>
Source§impl<K, N, M> Default for KeyNodeList<K, N, M>where
M: Default,
impl<K, N, M> Default for KeyNodeList<K, N, M>where
M: Default,
Source§impl<'a, K, N, M> Extend<&'a K> for KeyNodeList<K, N, M>
impl<'a, K, N, M> Extend<&'a K> for KeyNodeList<K, N, M>
Source§fn extend<I: IntoIterator<Item = &'a K>>(&mut self, iter: I)
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)
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<'a, K, T, N, M> Extend<(&'a K, &'a T)> for KeyNodeList<K, N, M>
impl<'a, K, T, N, M> Extend<(&'a K, &'a T)> for KeyNodeList<K, N, M>
Source§fn extend<I: IntoIterator<Item = (&'a K, &'a T)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (&'a K, &'a T)>>(&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, T, N, M> Extend<(K, T)> for KeyNodeList<K, N, M>
impl<K, T, N, M> Extend<(K, T)> for KeyNodeList<K, N, M>
Source§fn extend<I: IntoIterator<Item = (K, T)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (K, T)>>(&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, N, M> Extend<K> for KeyNodeList<K, N, M>
impl<K, N, M> Extend<K> for KeyNodeList<K, N, M>
Source§fn extend<I: IntoIterator<Item = K>>(&mut self, iter: I)
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)
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, T, N, M> FromIterator<(K, T)> for KeyNodeList<K, N, M>
impl<K, T, N, M> FromIterator<(K, T)> for KeyNodeList<K, N, M>
Source§impl<K, N, M> FromIterator<K> for KeyNodeList<K, N, M>
impl<K, N, M> FromIterator<K> for KeyNodeList<K, N, M>
Source§fn from_iter<I: IntoIterator<Item = K>>(iter: I) -> Self
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));