5 releases

0.1.4 Apr 10, 2024
0.1.3 Mar 20, 2024
0.1.2 Mar 25, 2023
0.1.1 Dec 21, 2022
0.1.0 Dec 18, 2022

#380 in Concurrency


Used in brck

MIT/Apache

18KB
333 lines

Parseq

Parseq is a Rust library crate that implements an extension trait adding parallel sequential mapping to the standard iterator trait.

See the crate documentation for more information.

Parseq's original source code is hosted here.

License

This work is distributed under the terms of both, the MIT License and the Apache License, Version 2.0.

Contribution

Contributions are welcome! Please contact me via email.


lib.rs:

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.

Dependencies

~345KB