Last active
January 17, 2017 16:32
-
-
Save bvssvni/cf1f63daa861415a83ab3f9d1eef2991 to your computer and use it in GitHub Desktop.
YEAH! It compiles!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn par_trans2( | |
pos: V2<f32>, | |
f: Box<Fn(&[V2<f32>], &mut [bool]) + Sync> | |
) -> Box<Fn(&[V2<f32>], &mut [bool]) + Sync>{ | |
const SIZE: usize = 1024; | |
Box::new(move |input, output| { | |
input.par_chunks(SIZE) | |
.zip(output.par_chunks_mut(SIZE)) | |
.for_each(|(i, o): (&[V2<f32>], &mut [bool])| { | |
/// Use stack memory to avoid allocations. | |
let mut i2: [V2<f32>; SIZE] = [V2 {x: 0.0, y: 0.0}; SIZE]; | |
for p in i2.iter_mut().take(i.len()) { | |
*p = *p - pos; | |
} | |
f(&i2[..i.len()], o) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a breakthrough because it might allow composing such functions together to perform parallel stream processing.