Hi.
I have a slice of some type T data: &[T] and slice of indices idx: &[usize].
The idx - is a indices that indicate where each subslice start and one extra element at the end which is the count of the data
for example:
let mut data = [1, 2, 3, 1, 2, 3, 4, 1, 2];
let idx = [0, 3, 7, 9];
// Idx is just encoded ranges 0..3 , 3..7 , 7..9 for indexing 'data'
// Result must be iterator by mut slices: &mut data[0..3], &mut data[3..7], &mut data[7..9]
Is it possible to make par iterator like this to mutate 'data'?
(hijacking the thread a little) I wanted to answer that in this case it'd be actually viable to directly implement ParallelIterator instead of regular Iterator + par_bridge, I've took a look at rayon internal readme and looks like it should be fairly possible to implement Producer (it requires implementation of split_at to "drive" the parallel iterator, which should be doable with split + split_at_mut), but... what now? I couldn't find a way of going from Producer to ParallelIterator. @alice, any ideas?
Oh, that's indeed helpful! And it's even linked from module docs:
If you’d like to build a custom parallel iterator, or to write your own combinator, then check out the split function and the plumbing module.
Perhaps too easy to miss though?
Anyway, looking at the source of Split showed me how to get ParallelIterator from Producer. I've even tried to implement IndexedParallelIterator. Seems to work! – Playground. I guess this should be slightly better than split, as rayon should be able to fall back to plain regular iteration for small chunks. (Or perhaps, if the chunks are not evenly sized, implementing IndexedParallelIterator is not a good idea?)
Anyway, there's really a lot of boilerplate – even though the implementation contains basically just three functions:
Iterator::next
Producer::split_at
len (separate impl in 4 traits ).
Perhaps I'm still missing some helper from rayon that would allow to cut on boilerplate?