SinglyIterable

Trait SinglyIterable 

Source
pub trait SinglyIterable<T, M, P>: HasSinglyEnds<T, M, P>
where M: MemoryPolicy<Singly<T>>, P: PinnedVec<Node<Singly<T>>>, Self: Sized,
{ // Provided methods fn iter_ptr<'a>(&'a self) -> SinglyIterPtr<'a, T, P> where M: 'a { ... } fn iter<'a>(&'a self) -> SinglyIter<'a, T, P> where M: 'a { ... } fn indices<'a>(&'a self) -> impl Iterator<Item = SinglyIdx<T>> where M: 'a, T: 'a, P: 'a { ... } fn pointers<'a>(&'a self) -> impl Iterator<Item = SinglyPtr<T>> where M: 'a, T: 'a, P: 'a { ... } fn iter_from<'a>(&'a self, idx: &SinglyIdx<T>) -> SinglyIter<'a, T, P> 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<'a, T, P>
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<'a, T, P>
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, P: '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 pointers<'a>(&'a self) -> impl Iterator<Item = SinglyPtr<T>>
where M: 'a, T: 'a, P: 'a,

Returns an iterator of pointers to the elements of the list.

Similar to indices, pointers are used to enable constant time access to any place of the list. They are thinner; however, have only some of the safety guarantees that indices have.

Source

fn iter_from<'a>(&'a self, idx: &SinglyIdx<T>) -> SinglyIter<'a, T, P>
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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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