Skip to content

6.0.0 — Swift 6

Latest

Choose a tag to compare

@dankogai dankogai released this 14 Aug 16:05

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, so m[i] needs no enumeration. Partial size is supported.
  • Permutations / Combinations — permutations/combinations of several sizes in one sequence, the counterpart of swift-algorithms' permutations(ofCount:) / combinations(ofCount:) with ranges. sizes: accepts any Sequence<Int>; size 0 contributes the empty element, so Combinations(of:s, sizes:0...n) is the power set grouped by size.

API changes (breaking)

  • The Combinatorics class namespace is gone. factorial(n), permutation(n, k), and combination(n, k) are now top-level generic functions over SignedInteger; factoradic() and combinadic(k) are methods on SignedInteger.
  • 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 on Int).
  • Combination's subscript maintains the binomial incrementally while unranking, cutting an access from O(n·k²) to O(n) multiplications.
  • Fixed Combination with default size returning empty arrays instead of the full combination.
  • Fixed Permutation trapping on an empty seed.

Housekeeping

  • Tests migrated from XCTest to Swift Testing, with expanded coverage.
  • BigCombinatorics now 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).