-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: add prevPermutation
, nextPermutationBy
and a version of nextPermutation
that goes back to the first perm?
#499
Comments
I think adding full complement of I'm not sure about primed versions. Whether it's good idea to expand API that much. That's also poor naming prime s usually reserved for indication of strictness P.S. I didn't get to benchmarking of PR yet. It's pity we don't have way to ask GHC to specialize large functions very aggressively instead of inlining them |
Thanks for your comment. It looks like we're on the same page. Or can we just add some guide to the doc comment: -- | Compute the (lexicographically) next permutation of the given vector in-place.
-- Returns False when the input is the last permutation; in this case the vector
-- will not be updated, unlike the behavior of the C++ function
-- @std::next_permutation@.
--
-- If you want to align the behavior with the C++ version, you need to write the
-- following wrapper yourself:
-- > nextPermutationGoBack v = do
-- > res <- VGM.nextPermutation v
-- > if res then return () else VGM.reverse v
-- > return res Reply to P.S.: Indeed, it's pity. Take your time, it's only a day from the submission of my PR. |
I think we should first add four |
I'm working on it in #498. |
For the sake of the readability of this issue itself: we have added During the implementation of #498, I think I have devised a suitable naming convention: Regarding the necessity of the primed/"bijective" versions, they have many useful properties for testing and benchmarking |
Another naming possibility is to use |
True. If we prioritize grammatical readability, we could add |
When I was authoring #498, I noticed that there is no implementation of
prevPermutation
ornextPermutationBy
. I also got surprised thatnextPermutation
, unlike in C++, does not go back to the first permutation when the argument holds the last permutation (I understand the reason for the decision, though). What do you think of adding the functions below? I'm not sure especially about the prime versions of the functions, but it doesn't hurt to record the idea, anyway.Update: In #498, we have added
(next|prev)Permutation(By)?
. The only remaining task is to decide whether we should add the primed versions(next|prev)Permutation(By)?'
and devise a better naming convention instead of using primes.Note: the implementation can be done in one function:
The text was updated successfully, but these errors were encountered: