Batched collections iteration?


#1

I’ve recently read this short blog post:

It looks a bit like the opposite of this paper:

http://lafstern.org/matt/segmented.pdf

So is it worth adding a segmented API to the iteration of Rust stdlib HashSet, HashMap, BTreeSet, BTreeMap?


#2

Rust’s design helps a bunch here in that internal iteration can already choose to use nested loops if that’s better for the structure in question. For example, https://doc.rust-lang.org/1.25.0/src/alloc/vec_deque.rs.html#1958-1964

I think I’d always rather refactor a for loop to .for_each() over refactoring to nested-for-using-batched. (Or try_for_each, in 1.27, if I need early-exit.)

Also, I think Rust’s HashMap doesn’t use buckets, so doesn’t actually need batched/segmented iteration…