use crate::concurrent_iter::ConcurrentIter;
pub struct EnumeratedItemPuller<'a, I>
where
I: ConcurrentIter,
{
con_iter: &'a I,
}
impl<I: ConcurrentIter> EnumeratedItemPuller<'_, I> {
#[inline(always)]
pub fn next_by(&mut self, thread_idx: usize) -> Option<(usize, I::Item)> {
self.con_iter.next_with_idx_by(thread_idx)
}
}
impl<'i, I> From<&'i I> for EnumeratedItemPuller<'i, I>
where
I: ConcurrentIter,
{
fn from(con_iter: &'i I) -> Self {
Self { con_iter }
}
}
impl<I> Iterator for EnumeratedItemPuller<'_, I>
where
I: ConcurrentIter,
{
type Item = (usize, I::Item);
#[inline(always)]
fn next(&mut self) -> Option<Self::Item> {
self.con_iter.next_with_idx()
}
fn size_hint(&self) -> (usize, Option<usize>) {
(0, self.con_iter.size_hint().1)
}
fn fold<B, F>(self, init: B, mut f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
{
let mut acc = init;
while let Some(elem) = self.con_iter.next_with_idx() {
acc = f(acc, elem);
}
acc
}
fn count(self) -> usize
where
Self: Sized,
{
self.fold(0, |count, _| count + 1)
}
}