orx_linked_list/iter/
doubly_link_iter.rs1use super::{DoublyLinkIterPtr, doubly_link_iter_ptr::PairPtr};
2use crate::Doubly;
3use core::iter::FusedIterator;
4use orx_pinned_vec::PinnedVec;
5use orx_selfref_col::{CoreCol, Node, NodePtr};
6
7pub struct DoublyLinkIter<'a, T, P>(DoublyLinkIterPtr<'a, T, P>)
11where
12 P: PinnedVec<Node<Doubly<T>>>;
13
14impl<'a, T, P> DoublyLinkIter<'a, T, P>
15where
16 P: PinnedVec<Node<Doubly<T>>>,
17{
18 pub(crate) fn new(
19 col: &'a CoreCol<Doubly<T>, P>,
20 current: Option<PairPtr<T>>,
21 current_back: Option<NodePtr<Doubly<T>>>,
22 ) -> Self {
23 Self(DoublyLinkIterPtr::new(col, current, current_back))
24 }
25}
26
27impl<'a, T, P> Iterator for DoublyLinkIter<'a, T, P>
28where
29 P: PinnedVec<Node<Doubly<T>>>,
30{
31 type Item = (&'a T, &'a T);
32
33 #[inline(always)]
34 fn next(&mut self) -> Option<Self::Item> {
35 self.0.next().map(|p| {
36 (unsafe { self.0.col.data_unchecked(p.0) }, unsafe {
37 self.0.col.data_unchecked(p.1)
38 })
39 })
40 }
41}
42
43impl<T, P> FusedIterator for DoublyLinkIter<'_, T, P> where P: PinnedVec<Node<Doubly<T>>> {}
44
45impl<T, P> Clone for DoublyLinkIter<'_, T, P>
46where
47 P: PinnedVec<Node<Doubly<T>>>,
48{
49 fn clone(&self) -> Self {
50 Self(self.0.clone())
51 }
52}