pub trait ExactSizeConcurrentIter: ConcurrentIter {
    // Required methods
    fn len(&self) -> usize;
    fn next_exact_chunk(
        &self,
        chunk_size: usize
    ) -> Option<NextManyExact<Self::Item, impl ExactSizeIterator<Item = Self::Item>>>;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A concurrent iterator that knows its exact length.

Required Methods§

source

fn len(&self) -> usize

Returns the exact remaining length of the concurrent iterator.

source

fn next_exact_chunk( &self, chunk_size: usize ) -> Option<NextManyExact<Self::Item, impl ExactSizeIterator<Item = Self::Item>>>

Returns the next chunk with the requested chunk_size:

  • Returns None if there are no more elements to yield.
  • Returns Some of a crate::NextManyExact which contains the following information:
    • begin_idx: the index of the first element to be yielded by the values iterator.
    • values: an ExactSizeIterator with known len which is guaranteed to be positive and less than or equal to chunk_size.
§Examples
use orx_concurrent_iter::*;
use orx_concurrent_bag::*;

let chunk_size = 2;
let num_threads = 4;

let characters = vec!['0', '1', '2', '3', '4', '5', '6', '7'];
let slice = characters.as_slice();

let outputs = ConcurrentBag::new();

let con_iter = &slice.con_iter();
let bag = &outputs;
std::thread::scope(|s| {
    for _ in 0..num_threads {
        s.spawn(move || {
            while let Some(next) = con_iter.next_exact_chunk(chunk_size) {
                let begin = next.begin_idx();
                for (i, value) in next.values().enumerate() {
                    let idx = begin + i;
                    let expected_value = char::from_digit(idx as u32, 10).unwrap();
                    assert_eq!(value, &expected_value);

                    bag.push(*value);
                }
            }
        });
    }
});

let mut outputs: Vec<char> = outputs.into_inner().into();
outputs.sort();
assert_eq!(characters, outputs);

Provided Methods§

source

fn is_empty(&self) -> bool

Returns true if the iterator is empty.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'a, T: Send + Sync + Clone> ExactSizeConcurrentIter for ClonedConIterOfSlice<'a, T>

source§

impl<'a, T: Send + Sync> ExactSizeConcurrentIter for ConIterOfSlice<'a, T>

source§

impl<Idx> ExactSizeConcurrentIter for ConIterOfRange<Idx>
where Idx: Send + Sync + Clone + Copy + From<usize> + Into<usize> + Add<Idx, Output = Idx> + Sub<Idx, Output = Idx> + Ord,

source§

impl<T: Send + Sync + Default> ExactSizeConcurrentIter for ConIterOfVec<T>

source§

impl<const N: usize, T: Send + Sync + Default> ExactSizeConcurrentIter for ConIterOfArray<N, T>