Crate parseq

source ·
Expand description

Parallel sequential iterator.

This crate implements an extension trait ParallelIterator adding parallel sequential mapping to the standard Iterator trait.

§Example

use std::time::Duration;
use parseq::ParallelIterator;

let mut iter = [3,2,1]
  .into_iter()
  .map_parallel(|i| {
    // Insert heavy computation here ...
    std::thread::sleep(Duration::from_millis(100*i));
    2*i
  });

assert_eq!(iter.next(), Some(6));
assert_eq!(iter.next(), Some(4));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), None);

See the examples directory for a real world example.

§Features

  • Parseq utilizes a configurable number of worker threads
  • Parseq preserves the order of the original iterator
  • Parseq is lazy in the sense that it doesn’t consume from the original iterator before next is called for the first time
  • Parseq doesn’t fuse the original iterator
  • Parseq uses constant space: linear in the number of threads and the size of the buffer, not in the length of the possibly infinite original iterator
  • Parseq propagates panics from the given closure

§Alternatives

If you don’t care about the order of the returned iterator you’ll probably want to use Rayon instead. If you do care about the order, take a look at Pariter. The latter provides more functionality than this crate and predates it.

Structs§

  • An iterator that maps the elements of another iterator in parallel.

Traits§