The version jumps to 6.0.0 to align with Swift 6: the package now requires swift-tools-version:6.0 and builds in the Swift 6 language mode. CI runs Swift 6.3 on macOS and Ubuntu.
New iterators
All random-accessible by index, like everything else in this package:
UniquePermutation— permutations of a multiset; duplicate elements yield each distinct ordering exactly once (UniquePermutation(of:"mississippi").count == 34650, not 11!). Counting and unranking use an exact integer DP, som[i]needs no enumeration. Partialsizeis supported.Permutations/Combinations— permutations/combinations of several sizes in one sequence, the counterpart of swift-algorithms'permutations(ofCount:)/combinations(ofCount:)with ranges.sizes:accepts anySequence<Int>; size 0 contributes the empty element, soCombinations(of:s, sizes:0...n)is the power set grouped by size.
API changes (breaking)
- The
Combinatoricsclass namespace is gone.factorial(n),permutation(n, k), andcombination(n, k)are now top-level generic functions overSignedInteger;factoradic()andcombinadic(k)are methods onSignedInteger. factoradic()takes no digit-count argument anymore — it returns the minimal representation.
Performance and fixes
combination(n, k)is computed multiplicatively: fewer operations, and intermediates no longer overflow when the result fits (combination(30, 15)used to trap onInt).Combination's subscript maintains the binomial incrementally while unranking, cutting an access from O(n·k²) to O(n) multiplications.- Fixed
Combinationwith default size returning empty arrays instead of the full combination. - Fixed
Permutationtrapping on an empty seed.
Housekeeping
- Tests migrated from XCTest to Swift Testing, with expanded coverage.
BigCombinatoricsnow depends on dankogai/swift-bignum instead of attaswift/BigInt.- The playground is restructured: one page per struct plus an arithmetic-functions page.
- README gains a comparison with swift-algorithms; the checked-in Xcode workspace and obsolete scripts are removed (Xcode opens Swift packages directly).