Struct orx_concurrent_iter::ConIterOfSlice
source · pub struct ConIterOfSlice<'a, T: Send + Sync> { /* private fields */ }
Expand description
A concurrent iterator over a slice yielding references to the elements.
Implementations§
Trait Implementations§
source§impl<'a, T: Send + Sync> AtomicIter<&'a T> for ConIterOfSlice<'a, T>
impl<'a, T: Send + Sync> AtomicIter<&'a T> for ConIterOfSlice<'a, T>
source§fn counter(&self) -> &AtomicCounter
fn counter(&self) -> &AtomicCounter
Returns a reference to the underlying advanced item counter.
source§fn progress_and_get_begin_idx(&self, number_to_fetch: usize) -> Option<usize>
fn progress_and_get_begin_idx(&self, number_to_fetch: usize) -> Option<usize>
Progresses the atomic counter by
number_to_fetch
elements and returns the beginning index of the elements to be fetched.
Returns None if the iterator is terminated and there are no more elements to be fetched. Read moresource§fn get(&self, item_idx: usize) -> Option<&'a T>
fn get(&self, item_idx: usize) -> Option<&'a T>
Returns the
item_idx
-th item that the iterator yields; returns None if the iterator completes before.source§fn fetch_n(
&self,
n: usize,
) -> Option<NextChunk<&'a T, impl ExactSizeIterator<Item = &'a T>>>
fn fetch_n( &self, n: usize, ) -> Option<NextChunk<&'a T, impl ExactSizeIterator<Item = &'a T>>>
Returns an iterator of the next
n
consecutive items that the iterator yields.
It might return an iterator of less or no items if the iteration does not have sufficient elements left.source§fn early_exit(&self)
fn early_exit(&self)
Skips all remaining elements of the iterator and assumes that the end of the iterator is reached. Read more
source§impl<'a, T: Send + Sync> AtomicIterWithInitialLen<&'a T> for ConIterOfSlice<'a, T>
impl<'a, T: Send + Sync> AtomicIterWithInitialLen<&'a T> for ConIterOfSlice<'a, T>
source§fn initial_len(&self) -> usize
fn initial_len(&self) -> usize
Returns the initial length of the atomic iterator.
source§impl<'a, T: Send + Sync> ConcurrentIter for ConIterOfSlice<'a, T>
impl<'a, T: Send + Sync> ConcurrentIter for ConIterOfSlice<'a, 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 vec: Vec<_> = (0..1024).map(|x| x.to_string()).collect();
let slice = vec.as_slice();
let con_iter = slice.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());
}
§type BufferedIter = BufferedSlice
type BufferedIter = BufferedSlice
Type of the buffered iterator returned by the
chunk_iter
method when elements are fetched in chunks by each thread.§type SeqIter = Skip<Iter<'a, T>>
type SeqIter = Skip<Iter<'a, T>>
Inner type which is the source of the data to be iterated, which in addition is a regular sequential
Iterator
.source§fn next_id_and_value(&self) -> Option<Next<Self::Item>>
fn next_id_and_value(&self) -> Option<Next<Self::Item>>
Advances the iterator and returns the next value together with its enumeration index. Read more
source§fn next_chunk(
&self,
chunk_size: usize,
) -> Option<NextChunk<Self::Item, impl ExactSizeIterator<Item = Self::Item>>>
fn next_chunk( &self, chunk_size: usize, ) -> Option<NextChunk<Self::Item, impl ExactSizeIterator<Item = Self::Item>>>
Advances the iterator
chunk_size
times and returns an iterator of at most chunk_size
consecutive next values.
Further, the beginning enumeration index of the yielded values is returned. Read moresource§fn buffered_iter(
&self,
chunk_size: usize,
) -> BufferedIter<'_, Self::Item, Self::BufferedIter>
fn buffered_iter( &self, chunk_size: usize, ) -> BufferedIter<'_, Self::Item, Self::BufferedIter>
Creates an iterator which pulls elements from this iterator as chunks of the given
chunk_size
. Read moresource§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 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 next(&self) -> Option<Self::Item>
fn next(&self) -> Option<Self::Item>
Advances the iterator and returns the next value. Read more
source§fn values(&self) -> ConIterValues<'_, Self> ⓘwhere
Self: Sized,
fn values(&self) -> ConIterValues<'_, Self> ⓘwhere
Self: Sized,
Returns an
Iterator
over the values of elements of the concurrent iterator. Read moresource§fn ids_and_values(&self) -> ConIterIdsAndValues<'_, Self> ⓘwhere
Self: Sized,
fn ids_and_values(&self) -> ConIterIdsAndValues<'_, Self> ⓘwhere
Self: Sized,
Returns an
Iterator
over the ids and values of elements of the concurrent iterator. Read moresource§fn for_each<Fun: FnMut(Self::Item)>(&self, chunk_size: usize, fun: Fun)where
Self: Sized,
fn for_each<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 enumerate_for_each<Fun: FnMut(usize, Self::Item)>(
&self,
chunk_size: usize,
fun: Fun,
)where
Self: Sized,
fn enumerate_for_each<Fun: FnMut(usize, Self::Item)>(
&self,
chunk_size: usize,
fun: Fun,
)where
Self: Sized,
Applies the function
fun
to each index and corresponding element of the iterator concurrently. Read moresource§impl<'a, T: Send + Sync> ExactSizeConcurrentIter for ConIterOfSlice<'a, T>
impl<'a, T: Send + Sync> ExactSizeConcurrentIter for ConIterOfSlice<'a, T>
source§impl<'a, T: Send + Sync + Clone> From<ConIterOfSlice<'a, T>> for ClonedConIterOfSlice<'a, T>
impl<'a, T: Send + Sync + Clone> From<ConIterOfSlice<'a, T>> for ClonedConIterOfSlice<'a, T>
source§fn from(iter: ConIterOfSlice<'a, T>) -> Self
fn from(iter: ConIterOfSlice<'a, T>) -> Self
Creates a concurrent iterator for the given slice
.
impl<'a, T: Send + Sync> Send for ConIterOfSlice<'a, T>
impl<'a, T: Send + Sync> Sync for ConIterOfSlice<'a, T>
Auto Trait Implementations§
impl<'a, T> !Freeze for ConIterOfSlice<'a, T>
impl<'a, T> RefUnwindSafe for ConIterOfSlice<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Unpin for ConIterOfSlice<'a, T>
impl<'a, T> UnwindSafe for ConIterOfSlice<'a, T>where
T: RefUnwindSafe,
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