pub struct ConIterOfIterX<T: Send + Sync, Iter>where
Iter: Iterator<Item = T>,{ /* private fields */ }Expand description
A regular Iter: Iterator ascended to the concurrent programs with use of atomics.
Since ConIterOfIter can wrap up any Iterator and enable concurrent iteration,
it might be considered as the most general ConcurrentIter implementation.
In performance critical scenarios and whenever possible, it might be preferable to use a more specific implementation such as crate::ConIterOfSlice.
Implementations§
Trait Implementations§
Source§impl<T: Send + Sync, Iter> ConcurrentIterX for ConIterOfIterX<T, Iter>where
Iter: Iterator<Item = T>,
impl<T: Send + Sync, Iter> ConcurrentIterX for ConIterOfIterX<T, Iter>where
Iter: Iterator<Item = T>,
Source§fn into_seq_iter(self) -> Self::SeqIter
fn into_seq_iter(self) -> Self::SeqIter
Converts the concurrent iterator back to the original wrapped type which is the source of the elements to be iterated. Already progressed elements are skipped.
§Examples
use orx_concurrent_iter::*;
let iter = (0..1024).map(|x| x.to_string());
let con_iter = iter.into_con_iter();
std::thread::scope(|s| {
s.spawn(|| {
for _ in 0..42 {
_ = con_iter.next();
}
let mut buffered = con_iter.buffered_iter(32);
let _chunk = buffered.next().unwrap();
});
});
let num_used = 42 + 32;
// converts the remaining elements into a sequential iterator
let seq_iter = con_iter.into_seq_iter();
assert_eq!(seq_iter.len(), 1024 - num_used);
for (i, x) in seq_iter.enumerate() {
assert_eq!(x, (num_used + i).to_string());
}Source§type SeqIter = Iter
type SeqIter = Iter
Inner type which is the source of the data to be iterated, which in addition is a regular sequential
Iterator.Source§type BufferedIterX = BufferIterX<T, Iter>
type BufferedIterX = BufferIterX<T, Iter>
Type of the buffered iterator returned by the
buffered_iter_x method when elements are fetched in chunks by each thread.Source§fn next(&self) -> Option<Self::Item>
fn next(&self) -> Option<Self::Item>
Advances the iterator and returns the next value. Read more
Source§fn next_chunk_x(
&self,
chunk_size: usize,
) -> Option<impl ExactSizeIterator<Item = Self::Item>>
fn next_chunk_x( &self, chunk_size: usize, ) -> Option<impl ExactSizeIterator<Item = Self::Item>>
Advances the iterator
chunk_size times and returns an iterator of at most chunk_size consecutive next values. Read moreSource§fn skip_to_end(&self)
fn skip_to_end(&self)
Skips all remaining elements of the iterator and assumes that the end of the iterator is reached. Read more
Source§fn try_get_len(&self) -> Option<usize>
fn try_get_len(&self) -> Option<usize>
Returns Some of the remaining length of the iterator if it is known; returns None otherwise.
Source§fn try_get_initial_len(&self) -> Option<usize>
fn try_get_initial_len(&self) -> Option<usize>
Returns Some of the initial length of the iterator when it was constructed if it is known; returns None otherwise. Read more
Source§fn values(&self) -> ConIterValuesX<'_, Self>where
Self: Sized,
fn values(&self) -> ConIterValuesX<'_, Self>where
Self: Sized,
Returns an
Iterator over the values of elements of the concurrent iterator. Read moreSource§fn for_each_x<Fun: FnMut(Self::Item)>(&self, chunk_size: usize, fun: Fun)where
Self: Sized,
fn for_each_x<Fun: FnMut(Self::Item)>(&self, chunk_size: usize, fun: Fun)where
Self: Sized,
Applies the function
fun to each element of the iterator concurrently. Read moreSource§fn fold<B, Fold>(&self, chunk_size: usize, neutral: B, fold: Fold) -> B
fn fold<B, Fold>(&self, chunk_size: usize, neutral: B, fold: Fold) -> B
Folds the elements of the iterator pulled concurrently using
fold function. Read moreSource§fn has_more(&self) -> HasMore
fn has_more(&self) -> HasMore
Returns whether or not the concurrent iterator has more elements to yield. Read more
Source§fn buffered_iter_x(
&self,
chunk_size: usize,
) -> BufferedIter<'_, Self::Item, Self::BufferedIterX>
fn buffered_iter_x( &self, chunk_size: usize, ) -> BufferedIter<'_, Self::Item, Self::BufferedIterX>
Creates an iterator which pulls elements from this iterator as chunks of the given
chunk_size. Read moreSource§impl<T: Send + Sync, Iter> From<Iter> for ConIterOfIterX<T, Iter>where
Iter: Iterator<Item = T>,
impl<T: Send + Sync, Iter> From<Iter> for ConIterOfIterX<T, Iter>where
Iter: Iterator<Item = T>,
impl<T: Send + Sync, Iter> Send for ConIterOfIterX<T, Iter>where
Iter: Iterator<Item = T>,
impl<T: Send + Sync, Iter> Sync for ConIterOfIterX<T, Iter>where
Iter: Iterator<Item = T>,
Auto Trait Implementations§
impl<T, Iter> !Freeze for ConIterOfIterX<T, Iter>
impl<T, Iter> !RefUnwindSafe for ConIterOfIterX<T, Iter>
impl<T, Iter> Unpin for ConIterOfIterX<T, Iter>where
Iter: Unpin,
impl<T, Iter> UnwindSafe for ConIterOfIterX<T, Iter>where
Iter: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more