Add uniquePermutations as wrapper for nextPermutation#91
Merged
Conversation
4 tasks
|
I think we actually want I just wanted this for #107 where I wrote: var tests: [[Int?]] = [
[],
[0],
[nil],
[0, nil],
[nil, 0],
[0, nil, 1, nil, 2, nil],
[0, 1, 2, nil, nil, nil],
[nil, nil, nil, 0, 1, 2],
]I would have preferred to write: let tests = [nil, nil, nil, 0, 1, 2].uniquePermutations(ofCount: 0)... which also would have given me more exhaustive test coverage. |
Member
Author
|
Totally agreed, though that points to the need for a let tests = [nil, nil, nil, 0, 1, 2]
.uniquePermutations(ofCount: 0...) { lhs, rhs in
rhs.map { rhs in lhs.map { lhs in lhs < rhs } ?? true } ?? false
} |
Member
Author
|
@swift-ci Please test |
1 similar comment
Member
Author
|
@swift-ci Please test |
2ff5a19 to
461208a
Compare
Member
Author
|
@swift-ci Please test |
Co-authored-by: Tim Vermeulen <tvermeulen@apple.com>
Member
Author
|
@swift-ci Please test |
timvermeulen
approved these changes
Mar 24, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds methods for generating the unique permutations of a sequence, as distinct from the position-based permutations generated by
permutations().Detailed Design
Includes new
uniquePermutations(ofCount:)methods (for both single counts and range expressions) and the wrappingUniquePermutationstype. The method requires that a collection's elements be hashable so that uniqueness can be determined in a pre-processing pass:Documentation Plan
I've added API documentation on the new methods and type, and have updated
Permutations.mdto include information about unique permutations.Test Plan
I've created tests in the
UniquePermutationsTests.swiftfile.Source Impact
None, additive only.
Checklist