Skip to content

Commit

Permalink
Fix a bug in the handling of producers
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Apr 11, 2019
1 parent 208ff7c commit c4da872
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 0.1.1

Fixed a bug in `MapfoldReduceProducerIter::next_back` discovered by @cuviper.

# 0.1.0

Initial release!
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "rayon_croissant"
version = "0.1.0" # don't forget to update documentation link on bump
version = "0.1.1" # don't forget to update documentation link on bump
authors = ["Anthony Ramine <n.oxyde@gmail.com>"]
description = "<lqd> bikeshedding the name: something that is mapped folded and collected, a 🥐"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/nox/rayon_croissant"
documentation = "https://docs.rs/rayon_croissant/0.1.0/"
documentation = "https://docs.rs/rayon_croissant/0.1.1/"
readme = "README.md"
categories = ["concurrency", "data-structures"]
keywords = ["arc", "split", "atomic", "thread"]
Expand Down
1 change: 1 addition & 0 deletions src/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ where
let input = self.input_iter.next_back()?;
let mut singleton = Target::default();
let output = (self.mapfold)(&mut singleton, input);
mem::swap(&mut self.back_sink, &mut singleton);
(self.reduce)(&mut self.back_sink, singleton);
Some(output)
}
Expand Down
35 changes: 35 additions & 0 deletions tests/producer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
extern crate rayon;
extern crate rayon_croissant;

use rayon::prelude::{ParallelIterator, IndexedParallelIterator, IntoParallelRefIterator};
use rayon_croissant::ParallelIteratorExt;

#[test]
fn test_zip_rev() {
let ingredients = &["jambon", "beurre", "fromage", "baguette"];
let scores = &[0, 1, 2, 3];

let mut names = vec![];
let rev_scores = ingredients
.par_iter()
.cloned()
.zip(scores.par_iter().cloned())
.with_min_len(2)
.mapfold_reduce_into(
&mut names,
|names, (name, score)| {
names.push(name);
score
},
|left_names, mut right_names| {
left_names.append(&mut right_names);
},
)
// Reversing *after* a call to mapfold_reduce_into shouldn't
// change the result of the folding operation.
.rev()
.collect::<Vec<_>>();

assert_eq!(names, ingredients);
assert_eq!(rev_scores, [3, 2, 1, 0]);
}

0 comments on commit c4da872

Please sign in to comment.