dynamically extendable Rayon parallel iterator
Find a file
Harald Hoyer e52693af8d
Merge pull request #5 from haraldh/lockless
Change lib to handle lockless collections
2020-07-20 13:49:37 +02:00
.github/workflows Add cargo fmt to github actions 2020-06-25 00:23:24 +02:00
src Change lib to handle lockless collections 2020-07-20 13:46:14 +02:00
.gitignore initial commit 2020-05-26 00:32:03 +02:00
Cargo.toml Change lib to handle lockless collections 2020-07-20 13:46:14 +02:00
LICENSE initial commit 2020-05-26 00:32:03 +02:00
README.md Change lib to handle lockless collections 2020-07-20 13:46:14 +02:00

Rust Coverage Status

DynQueue - dynamically extendable Rayon parallel iterator

A DynQueue<T> can be iterated with into_par_iter producing (DynQueueHandle, T) elements. With the DynQueueHandle<T> a new T can be inserted in the DynQueue<T>, which is currently iterated over.

A Vec<T>, VecDeque<T> and crossbeam_queue::SegQueue<T> (with feature = "crossbeam-queue") can be turned into a DynQueue<T> with .into_dyn_queue().

use rayon::iter::IntoParallelIterator as _;
use rayon::iter::ParallelIterator as _;

use dynqueue::IntoDynQueue as _;

fn main() {
    let mut result = vec![1, 2, 3]
        .into_dyn_queue()
        .into_par_iter()
        .map(|(handle, value)| { if value == 2 { handle.enqueue(4) }; value })
        .collect::<Vec<_>>();
    result.sort();

    assert_eq!(result, vec![1, 2, 3, 4]);
}

Features

  • crossbeam-queue : to use crossbeam::queue::SegQueue as the inner collection.