Trait orx_concurrent_iter::ConcurrentIter
source · pub trait ConcurrentIter: Send + Sync {
type Item: Send + Sync;
// Required methods
fn next_id_and_value(&self) -> Option<Next<Self::Item>>;
fn next_chunk(&self, chunk_size: usize) -> impl NextChunk<Self::Item>;
// Provided methods
fn next(&self) -> Option<Self::Item> { ... }
fn values(&self) -> ConIterValues<'_, Self> ⓘ
where Self: Sized { ... }
fn ids_and_values(&self) -> ConIterIdsAndValues<'_, Self> ⓘ
where Self: Sized { ... }
}
Expand description
Trait defining a concurrent iterator with next
and next_id_and_chunk
methods which can safely be called my multiple threads concurrently.
Required Associated Types§
Required Methods§
sourcefn 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.
Returns None when iteration is finished.
sourcefn next_chunk(&self, chunk_size: usize) -> impl NextChunk<Self::Item>
fn next_chunk(&self, chunk_size: usize) -> impl NextChunk<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.
This method:
- returns an iterator of
chunk_size
elements if there exists sufficient elements left in the iteration, or - it might return an iterator of
m < chunk_size
elements if there exists onlym
elements left, or - it might return an empty iterator.
This call would be equivalent to calling next_id_and_value
method chunk_size
times in a single-threaded execution.
However, calling next
method chunk_size
times in a concurrent execution does not guarantee to return chunk_size
consecutive elements.
On the other hand, next_id_and_chunk
guarantees that it returns consecutive elements, preventing any intermediate calls.
Provided Methods§
sourcefn next(&self) -> Option<Self::Item>
fn next(&self) -> Option<Self::Item>
Advances the iterator and returns the next value.
Returns None when iteration is finished.
sourcefn 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.
The iterator’s next
method does nothing but call the next
; this iterator is only to allow for using for
loops directly.
sourcefn 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.
The iterator’s next
method does nothing but call the next_id_and_value
; this iterator is only to allow for using for
loops directly.