You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For one of my projects I wrote a small implementation of Heap's algorithm, which iterates through all permutations of an array by shuffling its elements in-place. It does so in a way that minimizes the number of moves.
I think this would deserve a place in Combinatorics.jl, but I can't figure out how to provide a useful generic implementation. Enumerating permutations in-place is only good if you do something at each step, so I'm not sure a standard iterator is the right choice. Right now, I'm leaning towards accepting a function as argument, which would be applied after each move. What do you think?
The text was updated successfully, but these errors were encountered:
I wonder if a standard iterator approach could make sense. The array is changing in place, so this likely would make sense for single threaded cases only. I think the state for the iterator could use the original array plus something to detect the last permutation. I think a for loop on that would do what was expected. There might be an issue with the standard implementation of collect, though, but that could be overridden to either throw an error, or to copy each permutation.
That said, though, I wonder if that would break some of the expectations around iterators. Maybe using foreach would fit better.
Hi there!
For one of my projects I wrote a small implementation of Heap's algorithm, which iterates through all permutations of an array by shuffling its elements in-place. It does so in a way that minimizes the number of moves.
I think this would deserve a place in Combinatorics.jl, but I can't figure out how to provide a useful generic implementation. Enumerating permutations in-place is only good if you do something at each step, so I'm not sure a standard iterator is the right choice. Right now, I'm leaning towards accepting a function as argument, which would be applied after each move. What do you think?
The text was updated successfully, but these errors were encountered: