Module jobsteal::iter
[−]
[src]
Jobsteal's Parallel iterators.
The Spliterator
trait handles parallel iteration,
and the Split
trait deals with items which can be the
base of a Spliterator.
Using Spliterators
, we can write code that feels single-threaded
and simple that actually gets dispatched optimally onto the thread pool.
Here's an example where we take a list of 16000 numbers, filter it by whether they're even, and then perform an action for each one...in parallel!
use jobsteal::{make_pool, IntoSpliterator, Spliterator}; let mut pool = make_pool(4).unwrap(); let v = (0..16000).collect::<Vec<_>>(); v.into_split_iter() .filter(|&x| x % 2 == 0) // only even numbers allowed! .for_each(&pool.spawner(), |x| drop(x)); // do an action for each item!
These Spliterator
s can be used almost exactly like Rust's normal iterators!
The only difference is that when they're being "consumed" by something like
for_each
, collect
, fold
, or any
, they take one of jobsteal's spawners
as an argument. This allows them to distribute the work across the threads of
the pool the spawner is a handle for.
Reexports
pub use self::collect::Combine; |
Modules
all_any |
Whether all or any of the elements in a |
collect |
Collect Spliterators into collections. |
fold |
Fold or reduce the items of a |
Structs
Cloned | |
CostMul |
A cost multiplier.
See the docs of |
Enumerate |
Enumerate iterator adapter |
Filter |
Filter ilterator adapter. |
FlatMap |
Flat Mapping iterator adapter. |
Hide |
Used to mask data so that implementations don't conflict. |
Map |
Map iterator adapter. |
SliceSplit |
A split iterator over an immutable slice. |
SliceSplitMut |
A split iterator over a mutable slice. |
Zip |
Zip iterator adapter. |
Traits
BorrowSpliterator |
Things that can have a |
BorrowSpliteratorMut |
Things that can have a |
Callback |
A callback which takes an iterator of the given item type, processes it, and produces a result. |
Consumer |
A consumer takes an |
ExactSizeSpliterator |
An iterator for which the exact number of elements is known. |
IntoSpliterator |
Things that can be turned into a |
Split |
Data which can be split in two at an index. |
Spliterator |
A parallel iterator which works by splitting the underlying data and sharing it between threads. |