Skip to content

Conversation

chrisbouchard
Copy link

I think it could be handy to have a way to permute a slice without requiring T: Clone and without allocating a Vec. This method does the permutation in-place by swapping elements. The trade-off is that it has a worse asymptotic running time — O(n²) worst-case for cyclic permutations, but (I believe) O(n log n) expected since most permutations don't have large cycles. (The slow-down comes from having to chase cycles to figure out which elements to swap.)

This method (as the name implies) permutes the target slice in-place with
constant space rather than allocating a clone. The trade-off is worse asymptotic
running time for large permutations with large cycles -- O(n^2) worst-case, but
O(n log n) expected since most permutations don't have large cycles.
@chrisbouchard chrisbouchard force-pushed the feature/permute_in_place branch from 3f5ab0f to 6cbedbb Compare September 6, 2022 01:00
@chrisbouchard
Copy link
Author

I've removed the left-over dbg! calls. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant