I’ve been trying to contribute to statrs recently, and one of the issues I’ve been running into is that I’m trying to have an iterator that returns items in sorted order without cloning the underlying data. I’m working this PR if you wanted to take a look at my code so far. I looked up this problem and found this StackOverflow post about this topic from years ago but, frankly, I don’t believe it. Assuming you’re iterating from a vector, mutating the underlying vector is akin to keeping state on the order of the vector. Why cant that happen in a separate data structure? Is there a more efficient way to represent ordinality other than a vector? Creating an iterator is simply tracking traversal through that structure, which I think could be done using a bloom filter to track which indices have not been traversed yet. That just leaves the traversal algorithm itself. What information would an iterator need to know to make the best decision? Could I adapt a sorting algorithm to be an iterator?
I’m asking a lot of questions because I’m a statistics guys, not an algorithms guy. Any starting point or input is much appreciated!

That’s essentially where the code started, where the vector was presorted, then moved to a function to be used for a calculation. I want to have the caller be able to pass a borrow of a collection, for the purposes of this problem right now a fixed size vector, and not have to move the vector into the function. The function needs the sorted data, but doesn’t need to clone any of the data, just needs to run a calculation over it. Ideally the final implementation can a) take a borrow to a fixed size vector and b) not clone any of the underlying data in order to run its own calculations. The solution I’m toying with now is a sorted iterator, which shouldn’t clone the underlying vector’s data and should traverse the fixed size vector in a sorted order. Having an iterator whose
nextreturns sorted items from the fixed size vector would be the perfect solution to this issue.