Trait orx_linked_list::SinglyIterable

source ·
pub trait SinglyIterable<T, M>: HasSinglyEnds<T, M>
where M: MemoryPolicy<Singly<T>>, Self: Sized,
{ // Provided methods fn iter_ptr<'a>(&'a self) -> SinglyIterPtr<'_, T> where M: 'a { ... } fn iter<'a>(&'a self) -> SinglyIter<'_, T> where M: 'a { ... } fn indices<'a>(&'a self) -> impl Iterator<Item = SinglyIdx<T>> where M: 'a, T: 'a { ... } fn iter_from<'a>(&'a self, idx: &SinglyIdx<T>) -> SinglyIter<'_, T> where M: 'a { ... } fn eq_to_iter_vals<I>(&self, iter: I) -> bool where I: IntoIterator<Item = T>, T: PartialEq { ... } fn eq_to_iter_refs<'a, I>(&self, iter: I) -> bool where I: IntoIterator<Item = &'a T>, T: 'a + PartialEq { ... } }
Expand description

Iterator methods for Singly linked lists.

Provided Methods§

source

fn iter_ptr<'a>(&'a self) -> SinglyIterPtr<'_, T>
where M: 'a,

Returns a double-ended iterator of pointers to the elements of the list from front to back.

source

fn iter<'a>(&'a self) -> SinglyIter<'_, T>
where M: 'a,

Returns a forward iterator to elements of the list from front to back.

§Examples
use orx_linked_list::*;

let mut list = SinglyList::new();

// a -> b -> c
list.push_front('c');
list.push_front('b');
list.push_front('a');

let mut iter = list.iter();

assert_eq!(Some(&'a'), iter.next());
assert_eq!(Some(&'b'), iter.next());
assert_eq!(Some(&'c'), iter.next());
assert!(iter.next().is_none());
source

fn indices<'a>(&'a self) -> impl Iterator<Item = SinglyIdx<T>>
where M: 'a, T: 'a,

Returns an iterator of indices of elements of the list.

Recall that indices are used to enable constant time access to any place of the list. Methods adding an element to the list such as push_front or insert return the corresponding index of the element.

This method, on the other hand, is useful to collect all indices at once, probably after a reorganization.

§Examples
use orx_linked_list::*;

let mut list = SinglyList::new();

list.push_front(2);
list.push_front(1);
list.push_front(0);
assert!(list.eq_to_iter_vals([0, 1, 2]));

let idx: Vec<_> = list.indices().collect();

assert_eq!(list.get(&idx[1]), Some(&1));
source

fn iter_from<'a>(&'a self, idx: &SinglyIdx<T>) -> SinglyIter<'_, T>
where M: 'a,

Creates a forward iterator:

  • from the node with the given idx
  • to the back of the list.
§Panics

Panics if the index is invalid; i.e., idx_err does not return None.

§Example
use orx_linked_list::*;

let mut list = SinglyList::new();

list.push_front(3);
list.push_front(2);
let idx = list.push_front(1);
list.push_front(0); // 0->1->2->3

let mut iter = list.iter_from(&idx);
assert_eq!(iter.next(), Some(&1));
assert_eq!(iter.next(), Some(&2));
assert_eq!(iter.next(), Some(&3));
assert_eq!(iter.next(), None);
source

fn eq_to_iter_vals<I>(&self, iter: I) -> bool
where I: IntoIterator<Item = T>, T: PartialEq,

Returns true if the elements of the iterator are equal to those of the list.

source

fn eq_to_iter_refs<'a, I>(&self, iter: I) -> bool
where I: IntoIterator<Item = &'a T>, T: 'a + PartialEq,

Returns true if the elements of the iterator are equal to those of the list.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<L, T, M> SinglyIterable<T, M> for L
where L: HasSinglyEnds<T, M>, M: MemoryPolicy<Singly<T>>,