Explorar el Código

Add swift algorithms

jonfawcett hace 3 años
padre
commit
6d48ba274e
Se han modificado 34 ficheros con 8717 adiciones y 0 borrados
  1. 58 0
      Pods/Pods.xcodeproj/xcuserdata/jon.xcuserdatad/xcschemes/SwiftAlgorithms.xcscheme
  2. 211 0
      Pods/SwiftAlgorithms/LICENSE.txt
  3. 81 0
      Pods/SwiftAlgorithms/README.md
  4. 298 0
      Pods/SwiftAlgorithms/Sources/Algorithms/AdjacentPairs.swift
  5. 319 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Chain.swift
  6. 587 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Chunked.swift
  7. 299 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Combinations.swift
  8. 184 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Compacted.swift
  9. 222 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Cycle.swift
  10. 200 0
      Pods/SwiftAlgorithms/Sources/Algorithms/EitherSequence.swift
  11. 44 0
      Pods/SwiftAlgorithms/Sources/Algorithms/FirstNonNil.swift
  12. 311 0
      Pods/SwiftAlgorithms/Sources/Algorithms/FlattenCollection.swift
  13. 113 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Indexed.swift
  14. 669 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Intersperse.swift
  15. 489 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Joined.swift
  16. 484 0
      Pods/SwiftAlgorithms/Sources/Algorithms/MinMax.swift
  17. 206 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Partition.swift
  18. 592 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Permutations.swift
  19. 488 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Product.swift
  20. 620 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Reductions.swift
  21. 279 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Rotate.swift
  22. 756 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Split.swift
  23. 283 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Stride.swift
  24. 88 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Suffix.swift
  25. 240 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Trim.swift
  26. 145 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Unique.swift
  27. 360 0
      Pods/SwiftAlgorithms/Sources/Algorithms/Windows.swift
  28. 26 0
      Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms-Info.plist
  29. 5 0
      Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms-dummy.m
  30. 12 0
      Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms-prefix.pch
  31. 16 0
      Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms-umbrella.h
  32. 13 0
      Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms.debug.xcconfig
  33. 6 0
      Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms.modulemap
  34. 13 0
      Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms.release.xcconfig

+ 58 - 0
Pods/Pods.xcodeproj/xcuserdata/jon.xcuserdatad/xcschemes/SwiftAlgorithms.xcscheme

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "1240"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "YES"
+            buildForArchiving = "YES"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "2C511EE63C6E7D5843B971D1E441119E"
+               BuildableName = "Algorithms.framework"
+               BlueprintName = "SwiftAlgorithms"
+               ReferencedContainer = "container:Pods.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
+      </BuildActionEntries>
+   </BuildAction>
+   <TestAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      shouldUseLaunchSchemeArgsEnv = "YES">
+      <Testables>
+      </Testables>
+   </TestAction>
+   <LaunchAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      debugServiceExtension = "internal"
+      allowLocationSimulation = "YES">
+   </LaunchAction>
+   <ProfileAction
+      buildConfiguration = "Release"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      debugDocumentVersioning = "YES">
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>

+ 211 - 0
Pods/SwiftAlgorithms/LICENSE.txt

@@ -0,0 +1,211 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+    TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+    1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+    2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+    3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+    4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+    5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+    6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+    7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+    8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+    9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+    END OF TERMS AND CONDITIONS
+
+    APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+    Copyright [yyyy] [name of copyright owner]
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+
+
+## Runtime Library Exception to the Apache 2.0 License: ##
+
+
+    As an exception, if you use this Software to compile your source code and
+    portions of this Software are embedded into the binary product as a result,
+    you may redistribute such product without providing attribution as would
+    otherwise be required by Sections 4(a), 4(b) and 4(d) of the License.

+ 81 - 0
Pods/SwiftAlgorithms/README.md

@@ -0,0 +1,81 @@
+# Swift Algorithms
+
+**Swift Algorithms** is an open-source package of sequence and collection algorithms, along with their related types.
+
+Read more about the package, and the intent behind it, in the [announcement on swift.org](https://swift.org/blog/swift-algorithms/).
+
+## Contents
+
+#### Combinations / permutations
+
+- [`combinations(ofCount:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Combinations.md): Combinations of particular sizes of the elements in a collection.
+- [`permutations(ofCount:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Permutations.md): Permutations of a particular size of the elements in a collection, or of the full collection.
+- [`uniquePermutations(ofCount:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Permutations.md): Permutations of a collection's elements, skipping any duplicate permutations.
+
+#### Mutating algorithms
+
+- [`rotate(toStartAt:)`, `rotate(subrange:toStartAt:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Rotate.md): In-place rotation of elements.
+- [`stablePartition(by:)`, `stablePartition(subrange:by:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Partition.md): A partition that preserves the relative order of the resulting prefix and suffix.
+
+#### Combining collections
+
+- [`chain(_:_:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Chain.md): Concatenates two collections with the same element type. 
+- [`cycled()`, `cycled(times:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Cycle.md): Repeats the elements of a collection forever or a set number of times.
+- [`joined(by:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Joined.md): Concatenate sequences of sequences, using an element or sequence as a separator, or using a closure to generate each separator. 
+- [`product(_:_:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Product.md): Iterates over all the pairs of two collections; equivalent to nested `for`-`in` loops.
+
+#### Subsetting operations
+
+- [`compacted()`](https://github.com/apple/swift-algorithms/blob/main/Guides/Compacted.md): Drops the `nil`s from a sequence or collection, unwrapping the remaining elements.
+- [`randomSample(count:)`, `randomSample(count:using:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/RandomSampling.md): Randomly selects a specific number of elements from a collection.
+- [`randomStableSample(count:)`, `randomStableSample(count:using:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/RandomSampling.md): Randomly selects a specific number of elements from a collection, preserving their original relative order.
+- [`striding(by:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Stride.md): Returns every nth element of a collection.
+- [`suffix(while:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Suffix.md): Returns the suffix of a collection where all element pass a given predicate.
+- [`trimmingPrefix(while:)`, `trimmingSuffix(while)`, `trimming(while:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Trim.md): Returns a slice by trimming elements from a collection's start, end, or both. The mutating `trim...` methods trim a collection in place.
+- [`uniqued()`, `uniqued(on:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Unique.md): The unique elements of a collection, preserving their order.
+- [`minAndMax()`, `minAndMax(by:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/MinMax.md): Returns the smallest and largest elements of a sequence.
+
+#### Partial sorting
+
+- [`min(count:)`, `max(count:)`, `min(count:sortedBy:)`, `max(count:sortedBy:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/MinMax.md): Returns the smallest or largest elements of a collection, sorted by a predicate.
+
+#### Other useful operations
+
+- [`adjacentPairs()`](https://github.com/apple/swift-algorithms/blob/main/Guides/AdjacentPairs.md): Lazily iterates over tuples of adjacent elements.
+- [`chunked(by:)`, `chunked(on:)`, `chunks(ofCount:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Chunked.md): Eager and lazy operations that break a collection into chunks based on either a binary predicate or when the result of a projection changes or chunks of a given count.
+- [`firstNonNil(_:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/FirstNonNil.md): Returns the first non-`nil` result from transforming a sequence's elements.
+- [`indexed()`](https://github.com/apple/swift-algorithms/blob/main/Guides/Indexed.md): Iterate over tuples of a collection's indices and elements. 
+- [`interspersed(with:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Intersperse.md): Place a value between every two elements of a sequence.
+- [`partitioningIndex(where:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Partition.md): Returns the starting index of the partition of a collection that matches a predicate.
+- [`reductions(_:)`, `reductions(_:_:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Reductions.md): Returns all the intermediate states of reducing the elements of a sequence or collection.
+- [`split(maxSplits:omittingEmptySubsequences:whereSeparator)`, `split(separator:maxSplits:omittingEmptySubsequences)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Split.md): Lazy versions of the Standard Library's eager operations that split sequences and collections into subsequences separated by the specified separator element.
+- [`windows(ofCount:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Windows.md): Breaks a collection into overlapping subsequences where elements are slices from the original collection.
+
+## Adding Swift Algorithms as a Dependency
+
+To use the `Algorithms` library in a SwiftPM project, 
+add the following line to the dependencies in your `Package.swift` file:
+
+```swift
+.package(url: "https://github.com/apple/swift-algorithms", from: "1.0.0"),
+```
+
+Include `"Algorithms"` as a dependency for your executable target:
+
+```swift
+.target(name: "<target>", dependencies: [
+    .product(name: "Algorithms", package: "swift-algorithms"),
+]),
+```
+
+Finally, add `import Algorithms` to your source code.
+
+## Source Stability
+
+The Swift Numerics package is source stable; version numbers follow [Semantic Versioning](https://semver.org/). Source breaking changes to public API can only land in a new major version.
+
+The public API of version 1.0 of the `swift-algorithms` package consists of non-underscored declarations that are marked `public` in the `Algorithms` module. Interfaces that aren't part of the public API may continue to change in any release, including patch releases.
+
+Future minor versions of the package may introduce changes to these rules as needed.
+
+We'd like this package to quickly embrace Swift language and toolchain improvements that are relevant to its mandate. Accordingly, from time to time, we expect that new versions of this package will require clients to upgrade to a more recent Swift toolchain release. Requiring a new Swift release will only require a minor version bump.

+ 298 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/AdjacentPairs.swift

@@ -0,0 +1,298 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2021 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+extension Sequence {
+  /// Creates a sequence of adjacent pairs of elements from this sequence.
+  ///
+  /// In the `AdjacentPairsSequence` returned by this method, the elements of
+  /// the *i*th pair are the *i*th and *(i+1)*th elements of the underlying
+  /// sequence. The following example uses the `adjacentPairs()` method to
+  /// iterate over adjacent pairs of integers:
+  ///
+  ///     for pair in (1...).prefix(5).adjacentPairs() {
+  ///         print(pair)
+  ///     }
+  ///     // Prints "(1, 2)"
+  ///     // Prints "(2, 3)"
+  ///     // Prints "(3, 4)"
+  ///     // Prints "(4, 5)"
+  @inlinable
+  public func adjacentPairs() -> AdjacentPairsSequence<Self> {
+    AdjacentPairsSequence(base: self)
+  }
+}
+
+extension Collection {
+  /// A collection of adjacent pairs of elements built from an underlying
+  /// collection.
+  ///
+  /// In an `AdjacentPairsCollection`, the elements of the *i*th pair are the
+  /// *i*th and *(i+1)*th elements of the underlying sequence. The following
+  /// example uses the `adjacentPairs()` method to iterate over adjacent pairs
+  /// of integers:
+  ///
+  ///     for pair in (1...5).adjacentPairs() {
+  ///         print(pair)
+  ///     }
+  ///     // Prints "(1, 2)"
+  ///     // Prints "(2, 3)"
+  ///     // Prints "(3, 4)"
+  ///     // Prints "(4, 5)"
+  @inlinable
+  public func adjacentPairs() -> AdjacentPairsCollection<Self> {
+    AdjacentPairsCollection(base: self)
+  }
+}
+
+/// A sequence of adjacent pairs of elements built from an underlying sequence.
+///
+/// Use the `adjacentPairs()` method on a sequence to create an
+/// `AdjacentPairsSequence` instance.
+public struct AdjacentPairsSequence<Base: Sequence> {
+  @usableFromInline
+  internal let base: Base
+
+  /// Creates an instance that makes pairs of adjacent elements from `base`.
+  @inlinable
+  internal init(base: Base) {
+    self.base = base
+  }
+}
+
+extension AdjacentPairsSequence {
+  /// The iterator for an `AdjacentPairsSequence` or `AdjacentPairsCollection`
+  /// instance.
+  public struct Iterator {
+    @usableFromInline
+    internal var base: Base.Iterator
+
+    @usableFromInline
+    internal var previousElement: Base.Element?
+
+    @inlinable
+    internal init(base: Base.Iterator) {
+      self.base = base
+    }
+  }
+}
+
+extension AdjacentPairsSequence.Iterator: IteratorProtocol {
+  public typealias Element = (Base.Element, Base.Element)
+
+  @inlinable
+  public mutating func next() -> Element? {
+    if previousElement == nil {
+      previousElement = base.next()
+    }
+
+    guard let previous = previousElement, let next = base.next() else {
+      return nil
+    }
+
+    previousElement = next
+    return (previous, next)
+  }
+}
+
+extension AdjacentPairsSequence: Sequence {
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(base: base.makeIterator())
+  }
+
+  @inlinable
+  public var underestimatedCount: Int {
+    Swift.max(0, base.underestimatedCount - 1)
+  }
+}
+
+extension AdjacentPairsSequence: LazySequenceProtocol
+  where Base: LazySequenceProtocol {}
+
+/// A collection of adjacent pairs of elements built from an underlying
+/// collection.
+///
+/// Use the `adjacentPairs()` method on a collection to create an
+/// `AdjacentPairsCollection` instance.
+public struct AdjacentPairsCollection<Base: Collection> {
+  @usableFromInline
+  internal let base: Base
+
+  @usableFromInline
+  internal let secondBaseIndex: Base.Index
+
+  @inlinable
+  internal init(base: Base) {
+    self.base = base
+    self.secondBaseIndex = base.isEmpty
+      ? base.endIndex
+      : base.index(after: base.startIndex)
+  }
+}
+
+extension AdjacentPairsCollection {
+  /// A position in an `AdjacentPairsCollection` instance.
+  public struct Index: Comparable {
+    @usableFromInline
+    internal var first: Base.Index
+    
+    @usableFromInline
+    internal var second: Base.Index
+
+    @inlinable
+    internal init(first: Base.Index, second: Base.Index) {
+      self.first = first
+      self.second = second
+    }
+
+    @inlinable
+    public static func == (lhs: Index, rhs: Index) -> Bool {
+      lhs.first == rhs.first
+    }
+    
+    @inlinable
+    public static func < (lhs: Index, rhs: Index) -> Bool {
+      lhs.first < rhs.first
+    }
+  }
+}
+
+extension AdjacentPairsCollection: Collection {
+  @inlinable
+  public var startIndex: Index {
+    Index(
+      first: secondBaseIndex == base.endIndex ? base.endIndex : base.startIndex,
+      second: secondBaseIndex)
+  }
+  
+  @inlinable
+  public var endIndex: Index {
+    Index(first: base.endIndex, second: base.endIndex)
+  }
+
+  @inlinable
+  public subscript(position: Index) -> (Base.Element, Base.Element) {
+    (base[position.first], base[position.second])
+  }
+
+  @inlinable
+  public func index(after i: Index) -> Index {
+    precondition(i != endIndex, "Can't advance beyond endIndex")
+    let next = base.index(after: i.second)
+    return next == base.endIndex
+      ? endIndex
+      : Index(first: i.second, second: next)
+  }
+
+  @inlinable
+  public func index(_ i: Index, offsetBy distance: Int) -> Index {
+    guard distance != 0 else { return i }
+
+    guard let result = distance > 0
+      ? offsetForward(i, by: distance, limitedBy: endIndex)
+      : offsetBackward(i, by: -distance, limitedBy: startIndex)
+    else { fatalError("Index out of bounds") }
+    return result
+  }
+
+  @inlinable
+  public func index(
+    _ i: Index, offsetBy distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    guard distance != 0 else { return i }
+    guard limit != i else { return nil }
+    
+    if distance > 0 {
+      let limit = limit > i ? limit : endIndex
+      return offsetForward(i, by: distance, limitedBy: limit)
+    } else {
+      let limit = limit < i ? limit : startIndex
+      return offsetBackward(i, by: -distance, limitedBy: limit)
+    }
+  }
+  
+  @inlinable
+  internal func offsetForward(
+    _ i: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance > 0)
+    assert(limit > i)
+    
+    guard let newFirst = base.index(i.second, offsetBy: distance - 1, limitedBy: limit.first),
+          newFirst != base.endIndex
+    else { return nil }
+    let newSecond = base.index(after: newFirst)
+    
+    precondition(newSecond <= base.endIndex, "Can't advance beyond endIndex")
+    return newSecond == base.endIndex
+      ? endIndex
+      : Index(first: newFirst, second: newSecond)
+  }
+  
+  @inlinable
+  internal func offsetBackward(
+    _ i: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance > 0)
+    assert(limit < i)
+        
+    let offset = i == endIndex ? 0 : 1
+    guard let newSecond = base.index(
+      i.first,
+      offsetBy: -(distance - offset),
+      limitedBy: limit.second)
+    else { return nil }
+    let newFirst = base.index(newSecond, offsetBy: -1)
+    precondition(newFirst >= base.startIndex, "Can't move before startIndex")
+    return Index(first: newFirst, second: newSecond)
+  }
+
+  @inlinable
+  public func distance(from start: Index, to end: Index) -> Int {
+    // While there's a 2-step gap between the `first` base index values in
+    // `endIndex` and the penultimate index of this collection, the `second`
+    // base index values are consistently one step apart throughout the
+    // entire collection.
+    base.distance(from: start.second, to: end.second)
+  }
+
+  @inlinable
+  public var count: Int {
+    Swift.max(0, base.count - 1)
+  }
+}
+
+extension AdjacentPairsCollection: BidirectionalCollection
+  where Base: BidirectionalCollection
+{
+  @inlinable
+  public func index(before i: Index) -> Index {
+    precondition(i != startIndex, "Can't offset before startIndex")
+    let second = i == endIndex
+      ? base.index(before: base.endIndex)
+      : i.first
+    let first = base.index(before: second)
+    return Index(first: first, second: second)
+  }
+}
+
+extension AdjacentPairsCollection: RandomAccessCollection
+  where Base: RandomAccessCollection {}
+
+extension AdjacentPairsCollection: LazySequenceProtocol, LazyCollectionProtocol
+  where Base: LazySequenceProtocol {}
+
+extension AdjacentPairsCollection.Index: Hashable where Base.Index: Hashable {
+  @inlinable
+  public func hash(into hasher: inout Hasher) {
+    hasher.combine(first)
+  }
+}

+ 319 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Chain.swift

@@ -0,0 +1,319 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+/// A concatenation of two sequences with the same element type.
+public struct Chain2Sequence<Base1: Sequence, Base2: Sequence>
+  where Base1.Element == Base2.Element
+{
+  /// The first sequence in this chain.
+  @usableFromInline
+  internal let base1: Base1
+  
+  /// The second sequence in this chain.
+  @usableFromInline
+  internal let base2: Base2
+
+  @inlinable
+  internal init(base1: Base1, base2: Base2) {
+    self.base1 = base1
+    self.base2 = base2
+  }
+}
+
+extension Chain2Sequence: Sequence {
+  /// The iterator for a `Chain2Sequence` instance.
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal var iterator1: Base1.Iterator
+    
+    @usableFromInline
+    internal var iterator2: Base2.Iterator
+    
+    @inlinable
+    internal init(_ concatenation: Chain2Sequence) {
+      iterator1 = concatenation.base1.makeIterator()
+      iterator2 = concatenation.base2.makeIterator()
+    }
+    
+    @inlinable
+    public mutating func next() -> Base1.Element? {
+      return iterator1.next() ?? iterator2.next()
+    }
+  }
+  
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(self)
+  }
+}
+
+extension Chain2Sequence: Collection where Base1: Collection, Base2: Collection {
+  /// A position in a `Chain2Sequence` instance.
+  public struct Index: Comparable {
+    // The internal index representation, which can either be an index of the
+    // first collection or the second. The `endIndex` of the first collection
+    // is not to be used as a value - iterating over indices should go straight
+    // from the penultimate index of the first collection to the start of the
+    // second.
+    @usableFromInline
+    internal enum Representation: Equatable {
+      case first(Base1.Index)
+      case second(Base2.Index)
+    }
+
+    @usableFromInline
+    internal let position: Representation
+
+    /// Creates a new index into the first underlying collection.
+    @inlinable
+    internal init(first i: Base1.Index) {
+      position = .first(i)
+    }
+
+    /// Creates a new index into the second underlying collection.
+    @inlinable
+    internal init(second i: Base2.Index) {
+      position = .second(i)
+    }
+
+    @inlinable
+    public static func < (lhs: Index, rhs: Index) -> Bool {
+      switch (lhs.position, rhs.position) {
+      case (.first, .second):
+        return true
+      case (.second, .first):
+        return false
+      case let (.first(l), .first(r)):
+        return l < r
+      case let (.second(l), .second(r)):
+        return l < r
+      }
+    }
+  }
+  
+  /// Converts an index of `Base1` to the corresponding `Index` by mapping
+  /// `base1.endIndex` to `base2.startIndex`.
+  @inlinable
+  internal func normalizeIndex(_ i: Base1.Index) -> Index {
+    i == base1.endIndex ? Index(second: base2.startIndex) : Index(first: i)
+  }
+
+  @inlinable
+  public var startIndex: Index {
+    // if `base1` is empty, this will return `base2.startIndex` - if `base2` is
+    // also empty, this will correctly equal `base2.endIndex`
+    normalizeIndex(base1.startIndex)
+  }
+
+  @inlinable
+  public var endIndex: Index {
+    Index(second: base2.endIndex)
+  }
+
+  @inlinable
+  public subscript(i: Index) -> Base1.Element {
+    switch i.position {
+    case let .first(i):
+      return base1[i]
+    case let .second(i):
+      return base2[i]
+    }
+  }
+
+  @inlinable
+  public func index(after i: Index) -> Index {
+    switch i.position {
+    case let .first(i):
+      assert(i != base1.endIndex)
+      return normalizeIndex(base1.index(after: i))
+    case let .second(i):
+      return Index(second: base2.index(after: i))
+    }
+  }
+  
+  @inlinable
+  public func index(_ i: Index, offsetBy distance: Int) -> Index {
+    guard distance != 0 else { return i }
+    
+    return distance > 0
+      ? offsetForward(i, by: distance)
+      : offsetBackward(i, by: -distance)
+  }
+  
+  @inlinable
+  public func index(
+    _ i: Index,
+    offsetBy distance: Int,
+    limitedBy limit: Index
+  ) -> Index? {
+    if distance >= 0 {
+      return limit >= i
+        ? offsetForward(i, by: distance, limitedBy: limit)
+        : offsetForward(i, by: distance)
+    } else {
+      return limit <= i
+        ? offsetBackward(i, by: -distance, limitedBy: limit)
+        : offsetBackward(i, by: -distance)
+    }
+  }
+
+  @inlinable
+  internal func offsetForward(_ i: Index, by distance: Int) -> Index {
+    guard let index = offsetForward(i, by: distance, limitedBy: endIndex)
+      else { fatalError("Index is out of bounds") }
+    return index
+  }
+  
+  @inlinable
+  internal func offsetBackward(_ i: Index, by distance: Int) -> Index {
+    guard let index = offsetBackward(i, by: distance, limitedBy: startIndex)
+      else { fatalError("Index is out of bounds") }
+    return index
+  }
+
+  @inlinable
+  internal func offsetForward(
+    _ i: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance >= 0)
+    assert(limit >= i)
+    
+    switch (i.position, limit.position) {
+    case let (.first(i), .first(limit)):
+      return base1.index(i, offsetBy: distance, limitedBy: limit)
+        .map(Index.init(first:))
+    
+    case let (.first(i), .second(limit)):
+      if let j = base1.index(i, offsetBy: distance, limitedBy: base1.endIndex) {
+        // the offset stays within the bounds of `base1`
+        return normalizeIndex(j)
+      } else {
+        // the offset overflows the bounds of `base1` by `n - d`
+        let d = base1.distance(from: i, to: base1.endIndex)
+        return base2.index(base2.startIndex, offsetBy: distance - d, limitedBy: limit)
+          .map(Index.init(second:))
+      }
+      
+    case (.second, .first):
+      // impossible because `limit >= i`
+      fatalError()
+      
+    case let (.second(i), .second(limit)):
+      return base2.index(i, offsetBy: distance, limitedBy: limit)
+        .map(Index.init(second:))
+    }
+  }
+
+  @inlinable
+  internal func offsetBackward(
+    _ i: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance >= 0)
+    assert(limit <= i)
+    
+    switch (i.position, limit.position) {
+    case let (.first(i), .first(limit)):
+      return base1.index(i, offsetBy: -distance, limitedBy: limit)
+        .map(Index.init(first:))
+      
+    case (.first, .second):
+      // impossible because `limit <= i`
+      fatalError()
+      
+    case let (.second(i), .first(limit)):
+      if let j = base2.index(i, offsetBy: -distance, limitedBy: base2.startIndex) {
+        // the offset stays within the bounds of `base2`
+        return Index(second: j)
+      } else {
+        // the offset overflows the bounds of `base2` by `n - d`
+        let d = base2.distance(from: base2.startIndex, to: i)
+        return base1.index(base1.endIndex, offsetBy: -(distance - d), limitedBy: limit)
+          .map(Index.init(first:))
+      }
+
+    case let (.second(i), .second(limit)):
+      // `limit` is relevant, so `base1` cannot be reached
+      return base2.index(i, offsetBy: -distance, limitedBy: limit)
+        .map(Index.init(second:))
+    }
+  }
+  
+  @inlinable
+  public func distance(from start: Index, to end: Index) -> Int {
+    switch (start.position, end.position) {
+    case let (.first(i), .first(j)):
+      return base1.distance(from: i, to: j)
+    case let (.second(i), .second(j)):
+      return base2.distance(from: i, to: j)
+    case let (.first(i), .second(j)):
+      return base1.distance(from: i, to: base1.endIndex)
+        + base2.distance(from: base2.startIndex, to: j)
+    case let (.second(i), .first(j)):
+      return base2.distance(from: i, to: base2.startIndex)
+        + base1.distance(from: base1.endIndex, to: j)
+    }
+  }
+}
+
+extension Chain2Sequence: BidirectionalCollection
+  where Base1: BidirectionalCollection, Base2: BidirectionalCollection
+{
+  @inlinable
+  public func index(before i: Index) -> Index {
+    assert(i != startIndex, "Can't advance before startIndex")
+    switch i.position {
+    case let .first(i):
+      return Index(first: base1.index(before: i))
+    case let .second(i):
+      return i == base2.startIndex
+        ? Index(first: base1.index(before: base1.endIndex))
+        : Index(second: base2.index(before: i))
+    }
+  }
+}
+
+extension Chain2Sequence: RandomAccessCollection
+  where Base1: RandomAccessCollection, Base2: RandomAccessCollection {}
+
+//===----------------------------------------------------------------------===//
+// chain(_:_:)
+//===----------------------------------------------------------------------===//
+
+/// Returns a new sequence that iterates over the two given sequences, one
+/// followed by the other.
+///
+/// You can pass any two sequences or collections that have the same element
+/// type as this sequence. This example chains a closed range of `Int` with an
+/// array of `Int`:
+///
+///     let small = 1...3
+///     let big = [100, 200, 300]
+///     for num in chain(small, big) {
+///         print(num)
+///     }
+///     // 1
+///     // 2
+///     // 3
+///     // 100
+///     // 200
+///     // 300
+///
+/// - Parameters:
+///   - s1: The first sequence.
+///   - s2: The second sequence.
+/// - Returns: A sequence that iterates first over the elements of `s1`, and
+///   then over the elements of `s2`.
+///
+/// - Complexity: O(1)
+@inlinable
+public func chain<S1, S2>(_ s1: S1, _ s2: S2) -> Chain2Sequence<S1, S2> {
+  Chain2Sequence(base1: s1, base2: s2)
+}

+ 587 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Chunked.swift

@@ -0,0 +1,587 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+/// A collection wrapper that breaks a collection into chunks based on a
+/// predicate.
+///
+/// Call `lazy.chunked(by:)` on a collection to create an instance of this type.
+public struct ChunkedByCollection<Base: Collection, Subject> {
+  /// The collection that this instance provides a view onto.
+  @usableFromInline
+  internal let base: Base
+  
+  /// The projection function.
+  @usableFromInline
+  internal let projection: (Base.Element) -> Subject
+  
+  /// The predicate.
+  @usableFromInline
+  internal let belongInSameGroup: (Subject, Subject) -> Bool
+  
+  /// The end index of the first chunk.
+  @usableFromInline
+  internal var endOfFirstChunk: Base.Index
+  
+  @inlinable
+  internal init(
+    base: Base,
+    projection: @escaping (Base.Element) -> Subject,
+    belongInSameGroup: @escaping (Subject, Subject) -> Bool
+  ) {
+    self.base = base
+    self.projection = projection
+    self.belongInSameGroup = belongInSameGroup
+    self.endOfFirstChunk = base.startIndex
+    
+    if !base.isEmpty {
+      endOfFirstChunk = endOfChunk(startingAt: base.startIndex)
+    }
+  }
+}
+
+extension ChunkedByCollection: Collection {
+  /// A position in a chunked collection.
+  public struct Index: Comparable {
+    /// The range corresponding to the chunk at this position.
+    @usableFromInline
+    internal var baseRange: Range<Base.Index>
+    
+    @inlinable
+    internal init(_ baseRange: Range<Base.Index>) {
+      self.baseRange = baseRange
+    }
+    
+    @inlinable
+    public static func == (lhs: Index, rhs: Index) -> Bool {
+      // Since each index represents the range of a disparate chunk, no two
+      // unique indices will have the same lower bound.
+      lhs.baseRange.lowerBound == rhs.baseRange.lowerBound
+    }
+    
+    @inlinable
+    public static func < (lhs: Index, rhs: Index) -> Bool {
+      // Only use the lower bound to test for ordering, as above.
+      lhs.baseRange.lowerBound < rhs.baseRange.lowerBound
+    }
+  }
+
+  /// Returns the index in the base collection of the end of the chunk starting
+  /// at the given index.
+  @inlinable
+  internal func endOfChunk(startingAt start: Base.Index) -> Base.Index {
+    var subject = projection(base[start])
+    
+    return base[base.index(after: start)...].endOfPrefix(while: { element in
+      let nextSubject = projection(element)
+      defer { subject = nextSubject }
+      return belongInSameGroup(subject, nextSubject)
+    })
+  }
+  
+  @inlinable
+  public var startIndex: Index {
+    Index(base.startIndex..<endOfFirstChunk)
+  }
+  
+  @inlinable
+  public var endIndex: Index {
+    Index(base.endIndex..<base.endIndex)
+  }
+  
+  @inlinable
+  public func index(after i: Index) -> Index {
+    precondition(i != endIndex, "Can't advance past endIndex")
+    let upperBound = i.baseRange.upperBound
+    guard upperBound != base.endIndex else { return endIndex }
+    let end = endOfChunk(startingAt: upperBound)
+    return Index(upperBound..<end)
+  }
+  
+  @inlinable
+  public subscript(position: Index) -> Base.SubSequence {
+    precondition(position != endIndex, "Can't subscript using endIndex")
+    return base[position.baseRange]
+  }
+}
+
+extension ChunkedByCollection.Index: Hashable where Base.Index: Hashable {}
+
+extension ChunkedByCollection: BidirectionalCollection
+  where Base: BidirectionalCollection
+{
+  /// Returns the index in the base collection of the start of the chunk ending
+  /// at the given index.
+  @inlinable
+  internal func startOfChunk(endingAt end: Base.Index) -> Base.Index {
+    let indexBeforeEnd = base.index(before: end)
+    var subject = projection(base[indexBeforeEnd])
+    
+    return base[..<indexBeforeEnd].startOfSuffix(while: { element in
+      let nextSubject = projection(element)
+      defer { subject = nextSubject }
+      return belongInSameGroup(nextSubject, subject)
+    })
+  }
+
+  @inlinable
+  public func index(before i: Index) -> Index {
+    precondition(i != startIndex, "Can't advance before startIndex")
+    let start = startOfChunk(endingAt: i.baseRange.lowerBound)
+    return Index(start..<i.baseRange.lowerBound)
+  }
+}
+
+extension ChunkedByCollection: LazyCollectionProtocol {}
+
+/// A collection wrapper that breaks a collection into chunks based on a
+/// predicate.
+///
+/// Call `lazy.chunked(on:)` on a collection to create an instance of this type.
+public struct ChunkedOnCollection<Base: Collection, Subject: Equatable> {
+  @usableFromInline
+  internal var chunked: ChunkedByCollection<Base, Subject>
+  
+  @inlinable
+  internal init(
+    base: Base,
+    projection: @escaping (Base.Element) -> Subject
+  ) {
+    self.chunked = ChunkedByCollection(
+      base: base,
+      projection: projection,
+      belongInSameGroup: ==)
+  }
+}
+
+extension ChunkedOnCollection: Collection {
+  public typealias Index = ChunkedByCollection<Base, Subject>.Index
+  
+  @inlinable
+  public var startIndex: Index {
+    chunked.startIndex
+  }
+  
+  @inlinable
+  public var endIndex: Index {
+    chunked.endIndex
+  }
+  
+  @inlinable
+  public subscript(position: Index) -> (Subject, Base.SubSequence) {
+    let subsequence = chunked[position]
+    let subject = chunked.projection(subsequence.first!)
+    return (subject, subsequence)
+  }
+  
+  @inlinable
+  public func index(after i: Index) -> Index {
+    chunked.index(after: i)
+  }
+}
+
+extension ChunkedOnCollection: BidirectionalCollection
+  where Base: BidirectionalCollection
+{
+  @inlinable
+  public func index(before i: Index) -> Index {
+    chunked.index(before: i)
+  }
+}
+
+extension ChunkedOnCollection: LazyCollectionProtocol {}
+
+//===----------------------------------------------------------------------===//
+// lazy.chunked(by:) / lazy.chunked(on:)
+//===----------------------------------------------------------------------===//
+
+extension LazySequenceProtocol where Self: Collection, Elements: Collection {
+  /// Returns a lazy collection of subsequences of this collection, chunked by
+  /// the given predicate.
+  ///
+  /// - Complexity: O(*n*), because the start index is pre-computed.
+  @inlinable
+  public func chunked(
+    by belongInSameGroup: @escaping (Element, Element) -> Bool
+  ) -> ChunkedByCollection<Elements, Element> {
+    ChunkedByCollection(
+      base: elements,
+      projection: { $0 },
+      belongInSameGroup: belongInSameGroup)
+  }
+  
+  /// Returns a lazy collection of subsequences of this collection, chunked by
+  /// grouping elements that project to the same value.
+  ///
+  /// - Complexity: O(*n*), because the start index is pre-computed.
+  @inlinable
+  public func chunked<Subject>(
+    on projection: @escaping (Element) -> Subject
+  ) -> ChunkedOnCollection<Elements, Subject> {
+    ChunkedOnCollection(
+      base: elements,
+      projection: projection)
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// chunked(by:) / chunked(on:)
+//===----------------------------------------------------------------------===//
+
+extension Collection {
+  /// Returns a collection of subsequences of this collection, chunked by the
+  /// given predicate.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of this collection.
+  @inlinable
+  public func chunked(
+    by belongInSameGroup: (Element, Element) throws -> Bool
+  ) rethrows -> [SubSequence] {
+    guard !isEmpty else { return [] }
+    var result: [SubSequence] = []
+    
+    var start = startIndex
+    var current = self[start]
+    
+    for (index, element) in indexed().dropFirst() {
+      if try !belongInSameGroup(current, element) {
+        result.append(self[start..<index])
+        start = index
+      }
+      current = element
+    }
+    
+    if start != endIndex {
+      result.append(self[start...])
+    }
+    
+    return result
+  }
+
+  /// Returns a collection of subsequences of this collection, chunked by
+  /// grouping elements that project to the same value.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of this collection.
+  @inlinable
+  public func chunked<Subject: Equatable>(
+    on projection: (Element) throws -> Subject
+  ) rethrows -> [(Subject, SubSequence)] {
+    guard !isEmpty else { return [] }
+    var result: [(Subject, SubSequence)] = []
+    
+    var start = startIndex
+    var subject = try projection(self[start])
+    
+    for (index, element) in indexed().dropFirst() {
+      let nextSubject = try projection(element)
+      if subject != nextSubject {
+        result.append((subject, self[start..<index]))
+        start = index
+        subject = nextSubject
+      }
+    }
+    
+    if start != endIndex {
+      result.append((subject, self[start...]))
+    }
+    
+    return result
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// chunks(ofCount:)
+//===----------------------------------------------------------------------===//
+
+/// A collection that presents the elements of its base collection in
+/// `SubSequence` chunks of any given count.
+///
+/// A `ChunksOfCountCollection` is a lazy view on the base Collection, but it
+/// does not implicitly confer laziness on algorithms applied to its result. In
+/// other words, for ordinary collections `c`:
+///
+/// * `c.chunks(ofCount: 3)` does not create new storage
+/// * `c.chunks(ofCount: 3).map(f)` maps eagerly and returns a new array
+/// * `c.lazy.chunks(ofCount: 3).map(f)` maps lazily and returns a
+///   `LazyMapCollection`
+public struct ChunksOfCountCollection<Base: Collection> {
+  public typealias Element = Base.SubSequence
+  
+  @usableFromInline
+  internal let base: Base
+  
+  @usableFromInline
+  internal let chunkCount: Int
+  
+  @usableFromInline
+  internal var endOfFirstChunk: Base.Index
+
+  ///  Creates a view instance that presents the elements of `base` in
+  ///  `SubSequence` chunks of the given count.
+  ///
+  /// - Complexity: O(*n*), because the start index is pre-computed.
+  @inlinable
+  internal init(_base: Base, _chunkCount: Int) {
+    self.base = _base
+    self.chunkCount = _chunkCount
+    
+    // Compute the start index upfront in order to make start index a O(1)
+    // lookup.
+    self.endOfFirstChunk = _base.index(
+      _base.startIndex, offsetBy: _chunkCount,
+      limitedBy: _base.endIndex
+    ) ?? _base.endIndex
+  }
+}
+
+extension ChunksOfCountCollection: Collection {
+  public struct Index {
+    @usableFromInline
+    internal let baseRange: Range<Base.Index>
+    
+    @inlinable
+    internal init(_baseRange: Range<Base.Index>) {
+      self.baseRange = _baseRange
+    }
+  }
+
+  /// - Complexity: O(1)
+  @inlinable
+  public var startIndex: Index {
+    Index(_baseRange: base.startIndex..<endOfFirstChunk)
+  }
+  
+  @inlinable
+  public var endIndex: Index {
+    Index(_baseRange: base.endIndex..<base.endIndex)
+  }
+  
+  /// - Complexity: O(1)
+  @inlinable
+  public subscript(i: Index) -> Element {
+    precondition(i != endIndex, "Index out of range")
+    return base[i.baseRange]
+  }
+  
+  @inlinable
+  public func index(after i: Index) -> Index {
+    precondition(i != endIndex, "Advancing past end index")
+    let baseIdx = base.index(
+      i.baseRange.upperBound, offsetBy: chunkCount,
+      limitedBy: base.endIndex
+    ) ?? base.endIndex
+    return Index(_baseRange: i.baseRange.upperBound..<baseIdx)
+  }
+}
+
+extension ChunksOfCountCollection.Index: Comparable {
+  @inlinable
+  public static func == (lhs: ChunksOfCountCollection.Index,
+                         rhs: ChunksOfCountCollection.Index) -> Bool {
+    lhs.baseRange.lowerBound == rhs.baseRange.lowerBound
+  }
+  
+  @inlinable
+  public static func < (lhs: ChunksOfCountCollection.Index,
+                        rhs: ChunksOfCountCollection.Index) -> Bool {
+    lhs.baseRange.lowerBound < rhs.baseRange.lowerBound
+  }
+}
+
+extension ChunksOfCountCollection:
+  BidirectionalCollection, RandomAccessCollection
+where Base: RandomAccessCollection {
+  @inlinable
+  public func index(before i: Index) -> Index {
+    precondition(i != startIndex, "Advancing past start index")
+    
+    var offset = chunkCount
+    if i.baseRange.lowerBound == base.endIndex {
+      let remainder = base.count % chunkCount
+      if remainder != 0 {
+        offset = remainder
+      }
+    }
+    
+    let baseIdx = base.index(
+      i.baseRange.lowerBound, offsetBy: -offset,
+      limitedBy: base.startIndex
+    ) ?? base.startIndex
+    return Index(_baseRange: baseIdx..<i.baseRange.lowerBound)
+  }
+}
+
+extension ChunksOfCountCollection {
+  @inlinable
+  public func distance(from start: Index, to end: Index) -> Int {
+    let distance =
+      base.distance(from: start.baseRange.lowerBound,
+                    to: end.baseRange.lowerBound)
+    let (quotient, remainder) =
+      distance.quotientAndRemainder(dividingBy: chunkCount)
+    return quotient + remainder.signum()
+  }
+
+  @inlinable
+  public var count: Int {
+    let (quotient, remainder) =
+      base.count.quotientAndRemainder(dividingBy: chunkCount)
+    return quotient + remainder.signum()
+  }
+  
+  @inlinable
+  public func index(
+    _ i: Index, offsetBy offset: Int, limitedBy limit: Index
+  ) -> Index? {
+    guard offset != 0 else { return i }
+    guard limit != i else { return nil }
+    
+    if offset > 0 {
+      return limit > i
+        ? offsetForward(i, offsetBy: offset, limit: limit)
+        : offsetForward(i, offsetBy: offset)
+    } else {
+      return limit < i
+        ? offsetBackward(i, offsetBy: offset, limit: limit)
+        : offsetBackward(i, offsetBy: offset)
+    }
+  }
+
+  @inlinable
+  public func index(_ i: Index, offsetBy distance: Int) -> Index {
+    guard distance != 0 else { return i }
+    
+    let idx = distance > 0
+        ? offsetForward(i, offsetBy: distance)
+        : offsetBackward(i, offsetBy: distance)
+    guard let index = idx else {
+      fatalError("Out of bounds")
+    }
+    return index
+  }
+  
+  @inlinable
+  internal func offsetForward(
+    _ i: Index, offsetBy distance: Int, limit: Index? = nil
+  ) -> Index? {
+    assert(distance > 0)
+
+    return makeOffsetIndex(
+      from: i, baseBound: base.endIndex,
+      distance: distance, baseDistance: distance * chunkCount,
+      limit: limit, by: >
+    )
+  }
+  
+  // Convenience to compute offset backward base distance.
+  @inlinable
+  internal func computeOffsetBackwardBaseDistance(
+    _ i: Index, _ distance: Int
+  ) -> Int {
+    if i == endIndex {
+      let remainder = base.count%chunkCount
+      // We have to take it into account when calculating offsets.
+      if remainder != 0 {
+        // Distance "minus" one(at this point distance is negative) because we
+        // need to adjust for the last position that have a variadic(remainder)
+        // number of elements.
+        return ((distance + 1) * chunkCount) - remainder
+      }
+    }
+    return distance * chunkCount
+  }
+  
+  @inlinable
+  internal func offsetBackward(
+    _ i: Index, offsetBy distance: Int, limit: Index? = nil
+  ) -> Index? {
+    assert(distance < 0)
+    let baseDistance =
+        computeOffsetBackwardBaseDistance(i, distance)
+    return makeOffsetIndex(
+      from: i, baseBound: base.startIndex,
+      distance: distance, baseDistance: baseDistance,
+      limit: limit, by: <
+    )
+  }
+  
+  // Helper to compute index(offsetBy:) index.
+  @inlinable
+  internal func makeOffsetIndex(
+    from i: Index, baseBound: Base.Index, distance: Int, baseDistance: Int,
+    limit: Index?, by limitFn: (Base.Index, Base.Index) -> Bool
+  ) -> Index? {
+    let baseIdx = base.index(
+      i.baseRange.lowerBound, offsetBy: baseDistance,
+      limitedBy: baseBound
+    )
+    
+    if let limit = limit {
+      if baseIdx == nil {
+        // If we past the bounds while advancing forward and the limit is the
+        // `endIndex`, since the computation on base don't take into account the
+        // remainder, we have to make sure that passing the bound was because of
+        // the distance not just because of a remainder. Special casing is less
+        // expensive than always use count(which could be O(n) for non-random
+        // access collection base) to compute the base distance taking remainder
+        // into account.
+        if baseDistance > 0 && limit == endIndex {
+          if self.distance(from: i, to: limit) < distance {
+            return nil
+          }
+        } else {
+          return nil
+        }
+      }
+
+      // Checks for the limit.
+      let baseStartIdx = baseIdx ?? baseBound
+      if limitFn(baseStartIdx, limit.baseRange.lowerBound) {
+        return nil
+      }
+    }
+    
+    let baseStartIdx = baseIdx ?? baseBound
+    let baseEndIdx = base.index(
+      baseStartIdx, offsetBy: chunkCount, limitedBy: base.endIndex
+    ) ?? base.endIndex
+    
+    return Index(_baseRange: baseStartIdx..<baseEndIdx)
+  }
+}
+
+extension Collection {
+  /// Returns a `ChunksOfCountCollection<Self>` view presenting the elements in
+  /// chunks with count of the given count parameter.
+  ///
+  /// - Parameter count: The size of the chunks. If the count parameter is
+  ///   evenly divided by the count of the base `Collection` all the chunks will
+  ///   have the count equals to size. Otherwise, the last chunk will contain
+  ///   the remaining elements.
+  ///
+  ///     let c = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+  ///     print(c.chunks(ofCount: 5).map(Array.init))
+  ///     // [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
+  ///
+  ///     print(c.chunks(ofCount: 3).map(Array.init))
+  ///     // [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
+  ///
+  /// - Complexity: O(*n*), because the start index is pre-computed.
+  @inlinable
+  public func chunks(ofCount count: Int) -> ChunksOfCountCollection<Self> {
+    precondition(count > 0, "Cannot chunk with count <= 0!")
+    return ChunksOfCountCollection(_base: self, _chunkCount: count)
+  }
+}
+
+extension ChunksOfCountCollection.Index: Hashable where Base.Index: Hashable {}
+
+extension ChunksOfCountCollection: LazySequenceProtocol, LazyCollectionProtocol
+  where Base: LazySequenceProtocol {}

+ 299 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Combinations.swift

@@ -0,0 +1,299 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+/// A collection wrapper that generates combinations of a base collection.
+public struct CombinationsSequence<Base: Collection> {
+  /// The collection to iterate over for combinations.
+  @usableFromInline
+  internal let base: Base
+  
+  @usableFromInline
+  internal let baseCount: Int
+  
+  /// The range of accepted sizes of combinations.
+  ///
+  /// - Note: This may be `nil` if the attempted range entirely exceeds the
+  /// upper bounds of the size of the `base` collection.
+  @usableFromInline
+  internal let kRange: Range<Int>?
+  
+  /// Initializes a `CombinationsSequence` for all combinations of `base` of
+  /// size `k`.
+  ///
+  /// - Parameters:
+  ///   - base: The collection to iterate over for combinations.
+  ///   - k: The expected size of each combination.
+  @inlinable
+  internal init(_ base: Base, k: Int) {
+    self.init(base, kRange: k...k)
+  }
+  
+  /// Initializes a `CombinationsSequence` for all combinations of `base` of
+  /// sizes within a given range.
+  ///
+  /// - Parameters:
+  ///   - base: The collection to iterate over for combinations.
+  ///   - kRange: The range of accepted sizes of combinations.
+  @inlinable
+  internal init<R: RangeExpression>(
+    _ base: Base, kRange: R
+  ) where R.Bound == Int {
+    let range = kRange.relative(to: 0 ..< .max)
+    self.base = base
+    let baseCount = base.count
+    self.baseCount = baseCount
+    let upperBound = baseCount + 1
+    self.kRange = range.lowerBound < upperBound
+      ? range.clamped(to: 0 ..< upperBound)
+      : nil
+  }
+  
+  /// The total number of combinations.
+  @inlinable
+  public var count: Int {
+    guard let k = self.kRange else { return 0 }
+    let n = baseCount
+    if k == 0 ..< (n + 1) {
+      return 1 << n
+    }
+    
+    func binomial(n: Int, k: Int) -> Int {
+      switch k {
+      case n, 0: return 1
+      case n...: return 0
+      case (n / 2 + 1)...: return binomial(n: n, k: n - k)
+      default: return n * binomial(n: n - 1, k: k - 1) / k
+      }
+    }
+    
+    return k.map {
+      binomial(n: n, k: $0)
+    }.reduce(0, +)
+  }
+}
+
+extension CombinationsSequence: Sequence {
+  /// The iterator for a `CombinationsSequence` instance.
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal let base: Base
+    
+    /// The current range of accepted sizes of combinations.
+    ///
+    /// - Note: The range is contracted until empty while iterating over
+    /// combinations of different sizes. When the range is empty, iteration is
+    /// finished.
+    @usableFromInline
+    internal var kRange: Range<Int>
+    
+    /// Whether or not iteration is finished (`kRange` is empty)
+    @inlinable
+    internal var isFinished: Bool {
+      return kRange.isEmpty
+    }
+    
+    @usableFromInline
+    internal var indexes: [Base.Index]
+    
+    @inlinable
+    internal init(_ combinations: CombinationsSequence) {
+      self.base = combinations.base
+      self.kRange = combinations.kRange ?? 0..<0
+      self.indexes = Array(combinations.base.indices.prefix(kRange.lowerBound))
+    }
+    
+    /// Advances the current indices to the next set of combinations. If
+    /// `indexes.count == 3` and `base.count == 5`, the indices advance like
+    /// this:
+    ///
+    ///     [0, 1, 2]
+    ///     [0, 1, 3]
+    ///     [0, 1, 4] *
+    ///     // * `base.endIndex` reached in `indexes.last`
+    ///     // Advance penultimate index and propagate that change
+    ///     [0, 2, 3]
+    ///     [0, 2, 4] *
+    ///     [0, 3, 4] *
+    ///     [1, 2, 3]
+    ///     [1, 2, 4] *
+    ///     [1, 3, 4] *
+    ///     [2, 3, 4] *
+    ///     // Can't advance without needing to go past `base.endIndex`,
+    ///     // so the iteration is finished.
+    @inlinable
+    internal mutating func advance() {
+      /// Advances `kRange` by incrementing its `lowerBound` until the range is
+      /// empty, when iteration is finished.
+      func advanceKRange() {
+        if kRange.lowerBound < kRange.upperBound {
+          let advancedLowerBound = kRange.lowerBound + 1
+          kRange = advancedLowerBound ..< kRange.upperBound
+          indexes.removeAll(keepingCapacity: true)
+          indexes.append(contentsOf: base.indices.prefix(kRange.lowerBound))
+        }
+      }
+      
+      guard !indexes.isEmpty else {
+        // Initial state for combinations of 0 elements is an empty array with
+        // `finished == false`. Even though no indexes are involved, advancing
+        // from that state means we are finished with iterating.
+        advanceKRange()
+        return
+      }
+      
+      let i = indexes.count - 1
+      base.formIndex(after: &indexes[i])
+      if indexes[i] != base.endIndex { return }
+      
+      var j = i
+      while indexes[i] == base.endIndex {
+        j -= 1
+        guard j >= 0 else {
+          // Finished iterating over combinations of this size.
+          advanceKRange()
+          return
+        }
+        
+        base.formIndex(after: &indexes[j])
+        for k in indexes.indices[(j + 1)...] {
+          indexes[k] = base.index(after: indexes[k - 1])
+          if indexes[k] == base.endIndex {
+            break
+          }
+        }
+      }
+    }
+    
+    @inlinable
+    public mutating func next() -> [Base.Element]? {
+      guard !isFinished else { return nil }
+      defer { advance() }
+      return indexes.map { i in base[i] }
+    }
+  }
+  
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(self)
+  }
+}
+
+extension CombinationsSequence: LazySequenceProtocol
+  where Base: LazySequenceProtocol {}
+
+//===----------------------------------------------------------------------===//
+// combinations(ofCount:)
+//===----------------------------------------------------------------------===//
+
+extension Collection {
+  /// Returns a collection of combinations of this collection's elements, with
+  /// each combination having the specified number of elements.
+  ///
+  /// This example prints the different combinations of 1 and 2 from an array of
+  /// four colors:
+  ///
+  ///     let colors = ["fuchsia", "cyan", "mauve", "magenta"]
+  ///     for combo in colors.combinations(ofCount: 1...2) {
+  ///         print(combo.joined(separator: ", "))
+  ///     }
+  ///     // fuchsia
+  ///     // cyan
+  ///     // mauve
+  ///     // magenta
+  ///     // fuchsia, cyan
+  ///     // fuchsia, mauve
+  ///     // fuchsia, magenta
+  ///     // cyan, mauve
+  ///     // cyan, magenta
+  ///     // mauve, magenta
+  ///
+  /// The returned collection presents combinations in a consistent order, where
+  /// the indices in each combination are in ascending lexicographical order.
+  /// That is, in the example above, the combinations in order are the elements
+  /// at `[0]`, `[1]`, `[2]`, `[3]`, `[0, 1]`, `[0, 2]`, `[0, 3]`, `[1, 2]`,
+  /// `[1, 3]`, and finally `[2, 3]`.
+  ///
+  /// This example prints _all_ the combinations (including an empty array and
+  /// the original collection) from an array of numbers:
+  ///
+  ///     let numbers = [10, 20, 30, 40]
+  ///     for combo in numbers.combinations(ofCount: 0...) {
+  ///         print(combo)
+  ///     }
+  ///     // []
+  ///     // [10]
+  ///     // [20]
+  ///     // [30]
+  ///     // [40]
+  ///     // [10, 20]
+  ///     // [10, 30]
+  ///     // [10, 40]
+  ///     // [20, 30]
+  ///     // [20, 40]
+  ///     // [30, 40]
+  ///     // [10, 20, 30]
+  ///     // [10, 20, 40]
+  ///     // [10, 30, 40]
+  ///     // [20, 30, 40]
+  ///     // [10, 20, 30, 40]
+  ///
+  /// If `kRange` is `0...0`, the resulting sequence has exactly one element, an
+  /// empty array. The given range is limited to `0...base.count`. If the
+  /// limited range is empty, the resulting sequence has no elements.
+  ///
+  /// - Parameter kRange: The range of numbers of elements to include in each
+  ///   combination.
+  ///
+  /// - Complexity: O(1) for random-access base collections. O(*n*) where *n*
+  ///   is the number of elements in the base collection, since
+  ///   `CombinationsSequence` accesses the `count` of the base collection.
+  @inlinable
+  public func combinations<R: RangeExpression>(
+    ofCount kRange: R
+  ) -> CombinationsSequence<Self> where R.Bound == Int {
+    CombinationsSequence(self, kRange: kRange)
+  }
+  
+  /// Returns a collection of combinations of this collection's elements, with
+  /// each combination having the specified number of elements.
+  ///
+  /// This example prints the different combinations of three from an array of
+  /// four colors:
+  ///
+  ///     let colors = ["fuchsia", "cyan", "mauve", "magenta"]
+  ///     for combo in colors.combinations(ofCount: 3) {
+  ///         print(combo.joined(separator: ", "))
+  ///     }
+  ///     // fuchsia, cyan, mauve
+  ///     // fuchsia, cyan, magenta
+  ///     // fuchsia, mauve, magenta
+  ///     // cyan, mauve, magenta
+  ///
+  /// The returned collection presents combinations in a consistent order, where
+  /// the indices in each combination are in ascending lexicographical order.
+  /// That is, in the example above, the combinations in order are the elements
+  /// at `[0, 1, 2]`, `[0, 1, 3]`, `[0, 2, 3]`, and finally `[1, 2, 3]`.
+  ///
+  /// If `k` is zero, the resulting sequence has exactly one element, an empty
+  /// array. If `k` is greater than the number of elements in this sequence,
+  /// the resulting sequence has no elements.
+  ///
+  /// - Parameter k: The number of elements to include in each combination.
+  ///
+  /// - Complexity: O(1) for random-access base collections. O(*n*) where *n*
+  /// is the number of elements in the base collection, since
+  /// `CombinationsSequence` accesses the `count` of the base collection.
+  @inlinable
+  public func combinations(ofCount k: Int) -> CombinationsSequence<Self> {
+    precondition(k >= 0, "Can't have combinations with a negative number of elements.")
+    return CombinationsSequence(self, k: k)
+  }
+}

+ 184 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Compacted.swift

@@ -0,0 +1,184 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2021 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+/// A `Sequence` that iterates over every non-nil element from the original
+/// `Sequence`.
+public struct CompactedSequence<Base: Sequence, Element>: Sequence
+  where Base.Element == Element? {
+
+  @usableFromInline
+  let base: Base
+  
+  @inlinable
+  init(base: Base) {
+    self.base = base
+  }
+
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    var base: Base.Iterator
+    
+    @inlinable
+    init(base: Base.Iterator) {
+      self.base = base
+    }
+    
+    @inlinable
+    public mutating func next() -> Element? {
+      while let wrapped = base.next() {
+        guard let some = wrapped else { continue }
+        return some
+      }
+      return nil
+    }
+  }
+
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(base: base.makeIterator())
+  }
+}
+
+extension Sequence {
+  /// Returns a new `Sequence` that iterates over every non-nil element from the
+  /// original `Sequence`.
+  ///
+  /// Produces the same result as `c.compactMap { $0 }`.
+  ///
+  ///     let c = [1, nil, 2, 3, nil]
+  ///     for num in c.compacted() {
+  ///         print(num)
+  ///     }
+  ///     // 1
+  ///     // 2
+  ///     // 3
+  ///
+  /// - Returns: A `Sequence` where the element is the unwrapped original
+  ///   element and iterates over every non-nil element from the original
+  ///   `Sequence`.
+  ///
+  /// Complexity: O(1)
+  @inlinable
+  public func compacted<Unwrapped>() -> CompactedSequence<Self, Unwrapped>
+    where Element == Unwrapped? {
+    CompactedSequence(base: self)
+  }
+}
+
+/// A `Collection` that iterates over every non-nil element from the original
+/// `Collection`.
+public struct CompactedCollection<Base: Collection, Element>: Collection
+  where Base.Element == Element? {
+
+  @usableFromInline
+  let base: Base
+  
+  @inlinable
+  init(base: Base) {
+    self.base = base
+    let idx = base.firstIndex(where: { $0 != nil }) ?? base.endIndex
+    self.startIndex = Index(base: idx)
+  }
+  
+  public struct Index {
+    @usableFromInline
+    let base: Base.Index
+    
+    @inlinable
+    init(base: Base.Index) {
+      self.base = base
+    }
+  }
+  
+  public var startIndex: Index
+  
+  @inlinable
+  public var endIndex: Index { Index(base: base.endIndex) }
+  
+  @inlinable
+  public subscript(position: Index) -> Element {
+    base[position.base]!
+  }
+  
+  @inlinable
+  public func index(after i: Index) -> Index {
+    precondition(i != endIndex, "Index out of bounds")
+    
+    let baseIdx = base.index(after: i.base)
+    guard let idx = base[baseIdx...].firstIndex(where: { $0 != nil })
+      else { return endIndex }
+    return Index(base: idx)
+  }
+}
+
+extension CompactedCollection: BidirectionalCollection
+  where Base: BidirectionalCollection {
+
+  @inlinable
+  public func index(before i: Index) -> Index {
+    precondition(i != startIndex, "Index out of bounds")
+    
+    guard let idx =
+            base[startIndex.base..<i.base]
+                .lastIndex(where: { $0 != nil })
+      else { fatalError("Index out of bounds") }
+    return Index(base: idx)
+  }
+}
+
+extension CompactedCollection.Index: Comparable {  
+  @inlinable
+  public static func < (lhs: CompactedCollection.Index,
+                        rhs: CompactedCollection.Index) -> Bool {
+    lhs.base < rhs.base
+  }
+}
+
+extension CompactedCollection.Index: Hashable
+  where Base.Index: Hashable {}
+
+extension Collection {
+  /// Returns a new `Collection` that iterates over every non-nil element from
+  /// the original `Collection`.
+  ///
+  /// Produces the same result as `c.compactMap { $0 }`.
+  ///
+  ///     let c = [1, nil, 2, 3, nil]
+  ///     for num in c.compacted() {
+  ///         print(num)
+  ///     }
+  ///     // 1
+  ///     // 2
+  ///     // 3
+  ///
+  /// - Returns: A `Collection` where the element is the unwrapped original
+  ///   element and iterates over every non-nil element from the original
+  ///   `Collection`.
+  ///
+  /// Complexity: O(*n*) where *n* is the number of elements in the
+  /// original `Collection`.
+  @inlinable
+  public func compacted<Unwrapped>() -> CompactedCollection<Self, Unwrapped>
+    where Element == Unwrapped?
+  {
+    CompactedCollection(base: self)
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// Protocol Conformances
+//===----------------------------------------------------------------------===//
+
+extension CompactedSequence: LazySequenceProtocol
+  where Base: LazySequenceProtocol {}
+
+extension CompactedCollection: LazySequenceProtocol, LazyCollectionProtocol
+  where Base: LazySequenceProtocol {}

+ 222 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Cycle.swift

@@ -0,0 +1,222 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+/// A collection wrapper that repeats the elements of a base collection.
+public struct CycledSequence<Base: Collection> {
+  /// The collection to repeat.
+  @usableFromInline
+  internal let base: Base
+  
+  @inlinable
+  internal init(base: Base) {
+    self.base = base
+  }
+}
+
+extension CycledSequence: Sequence {
+  /// The iterator for a `CycledSequence` instance.
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal let base: Base
+    
+    @usableFromInline
+    internal var current: Base.Index
+    
+    @inlinable
+    internal init(base: Base) {
+      self.base = base
+      self.current = base.startIndex
+    }
+    
+    @inlinable
+    public mutating func next() -> Base.Element? {
+      guard !base.isEmpty else { return nil }
+      
+      if current == base.endIndex {
+        current = base.startIndex
+      }
+      
+      defer { base.formIndex(after: &current) }
+      return base[current]
+    }
+  }
+  
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(base: base)
+  }
+}
+
+extension CycledSequence: LazySequenceProtocol
+  where Base: LazySequenceProtocol {}
+
+/// A collection wrapper that repeats the elements of a base collection for a
+/// finite number of times.
+public struct CycledTimesCollection<Base: Collection> {
+  /// A `Product2Sequence` instance for iterating the base collection.
+  @usableFromInline
+  internal let product: Product2Sequence<Range<Int>, Base>
+
+  @inlinable
+  internal init(base: Base, times: Int) {
+    self.product = Product2Sequence(0..<times, base)
+  }
+}
+
+extension CycledTimesCollection: Collection {
+  public typealias Element = Base.Element
+
+  public struct Index: Comparable {
+    /// The index corresponding to the `Product2Sequence` index at this
+    /// position.
+    @usableFromInline
+    internal let productIndex: Product2Sequence<Range<Int>, Base>.Index
+
+    @inlinable
+    internal init(_ productIndex: Product2Sequence<Range<Int>, Base>.Index) {
+      self.productIndex = productIndex
+    }
+
+    @inlinable
+    public static func == (lhs: Index, rhs: Index) -> Bool {
+      lhs.productIndex == rhs.productIndex
+    }
+
+    @inlinable
+    public static func < (lhs: Index, rhs: Index) -> Bool {
+      lhs.productIndex < rhs.productIndex
+    }
+  }
+
+  @inlinable
+  public var startIndex: Index {
+    Index(product.startIndex)
+  }
+
+  @inlinable
+  public var endIndex: Index {
+    Index(product.endIndex)
+  }
+
+  @inlinable
+  public subscript(_ index: Index) -> Element {
+    product[index.productIndex].1
+  }
+
+  @inlinable
+  public func index(after i: Index) -> Index {
+    let productIndex = product.index(after: i.productIndex)
+    return Index(productIndex)
+  }
+
+  @inlinable
+  public func distance(from start: Index, to end: Index) -> Int {
+    product.distance(from: start.productIndex, to: end.productIndex)
+  }
+
+  @inlinable
+  public func index(_ i: Index, offsetBy distance: Int) -> Index {
+    let productIndex = product.index(i.productIndex, offsetBy: distance)
+    return Index(productIndex)
+  }
+
+  @inlinable
+  public func index(
+    _ i: Index,
+    offsetBy distance: Int,
+    limitedBy limit: Index
+  ) -> Index? {
+    guard let productIndex = product.index(
+      i.productIndex,
+      offsetBy: distance,
+      limitedBy: limit.productIndex)
+    else { return nil }
+    return Index(productIndex)
+  }
+
+  @inlinable
+  public var count: Int {
+    product.count
+  }
+}
+
+extension CycledTimesCollection: BidirectionalCollection
+  where Base: BidirectionalCollection {
+  @inlinable
+  public func index(before i: Index) -> Index {
+    let productIndex = product.index(before: i.productIndex)
+    return Index(productIndex)
+  }
+}
+
+extension CycledTimesCollection: RandomAccessCollection
+  where Base: RandomAccessCollection {}
+
+extension CycledTimesCollection: LazySequenceProtocol, LazyCollectionProtocol
+  where Base: LazySequenceProtocol {}
+
+//===----------------------------------------------------------------------===//
+// cycled()
+//===----------------------------------------------------------------------===//
+
+extension Collection {
+  /// Returns a sequence that repeats the elements of this collection forever.
+  ///
+  /// Use the `cycled()` method to repeat the elements of a sequence or
+  /// collection forever. You can combine `cycled()` with another, finite
+  /// sequence to iterate over the two together.
+  ///
+  ///     for (evenOrOdd, number) in zip(["even", "odd"].cycled(), 0..<10) {
+  ///         print("\(number) is \(evenOrOdd)")
+  ///     }
+  ///     // 0 is even
+  ///     // 1 is odd
+  ///     // 2 is even
+  ///     // 3 is odd
+  ///     // ...
+  ///     // 9 is odd
+  ///
+  /// - Important: When called on a non-empty collection, the resulting sequence
+  ///   is infinite. Do not directly call methods that require a finite
+  ///   sequence, like `map` or `filter`, without first constraining the length
+  ///   of the cycling sequence.
+  ///
+  /// - Returns: A sequence that repeats the elements of this collection
+  ///   forever.
+  ///
+  /// - Complexity: O(1)
+  @inlinable
+  public func cycled() -> CycledSequence<Self> {
+    CycledSequence(base: self)
+  }
+  
+  /// Returns a sequence that repeats the elements of this collection the
+  /// specified number of times.
+  ///
+  /// Passing `1` as `times` results in this collection's elements being
+  /// provided a single time; passing `0` results in an empty sequence. The
+  /// `print(_:)` function in this example is never called:
+  ///
+  ///     for x in [1, 2, 3].cycled(times: 0) {
+  ///         print(x)
+  ///     }
+  ///
+  /// - Parameter times: The number of times to repeat this sequence. `times`
+  ///   must be zero or greater.
+  /// - Returns: A sequence that repeats the elements of this sequence `times`
+  ///   times.
+  ///
+  /// - Complexity: O(1)
+  @inlinable
+  public func cycled(times: Int) -> CycledTimesCollection<Self> {
+    CycledTimesCollection(base: self, times: times)
+  }
+}

+ 200 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/EitherSequence.swift

@@ -0,0 +1,200 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2021 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// Either
+//===----------------------------------------------------------------------===//
+
+/// A general-purpose sum type.
+@usableFromInline
+internal enum Either<Left, Right> {
+  case left(Left)
+  case right(Right)
+}
+
+extension Either: Equatable where Left: Equatable, Right: Equatable {
+  @usableFromInline
+  internal static func == (lhs: Self, rhs: Self) -> Bool {
+    switch (lhs, rhs) {
+    case let (.left(lhs), .left(rhs)):
+      return lhs == rhs
+    case let (.right(lhs), .right(rhs)):
+      return lhs == rhs
+    case (.left, .right), (.right, .left):
+      return false
+    }
+  }
+}
+
+extension Either: Comparable where Left: Comparable, Right: Comparable {
+  @usableFromInline
+  internal static func < (lhs: Self, rhs: Self) -> Bool {
+    switch (lhs, rhs) {
+    case let (.left(lhs), .left(rhs)):
+      return lhs < rhs
+    case let (.right(lhs), .right(rhs)):
+      return lhs < rhs
+    case (.left, .right):
+      return true
+    case (.right, .left):
+      return false
+    }
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// EitherSequence
+//===----------------------------------------------------------------------===//
+
+/// A sequence that has one of the two specified types.
+@usableFromInline
+internal enum EitherSequence<Left: Sequence, Right: Sequence>
+  where Left.Element == Right.Element
+{
+  case left(Left)
+  case right(Right)
+}
+
+extension EitherSequence: Sequence {
+  @usableFromInline
+  internal struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal var left: Left.Iterator?
+    
+    @usableFromInline
+    internal var right: Right.Iterator?
+    
+    @inlinable
+    internal mutating func next() -> Left.Element? {
+      left?.next() ?? right?.next()
+    }
+  }
+  
+  @usableFromInline
+  internal func makeIterator() -> Iterator {
+    switch self {
+    case .left(let left):
+      return Iterator(left: left.makeIterator(), right: nil)
+    case .right(let right):
+      return Iterator(left: nil, right: right.makeIterator())
+    }
+  }
+}
+
+extension EitherSequence: Collection
+  where Left: Collection, Right: Collection, Left.Element == Right.Element
+{
+  @usableFromInline
+  internal typealias Index = Either<Left.Index, Right.Index>
+
+  @inlinable
+  internal var startIndex: Index {
+    switch self {
+    case .left(let s):
+      return .left(s.startIndex)
+    case .right(let s):
+      return .right(s.startIndex)
+    }
+  }
+
+  @inlinable
+  internal var endIndex: Index {
+    switch self {
+    case .left(let s):
+      return .left(s.endIndex)
+    case .right(let s):
+      return .right(s.endIndex)
+    }
+  }
+
+  @inlinable
+  internal subscript(position: Index) -> Element {
+    switch (self, position) {
+    case let (.left(s), .left(i)):
+      return s[i]
+    case let (.right(s), .right(i)):
+      return s[i]
+    default:
+      fatalError()
+    }
+  }
+
+  @inlinable
+  internal func index(after i: Index) -> Index {
+    switch (self,i) {
+    case let (.left(s), .left(i)):
+      return .left(s.index(after: i))
+    case let (.right(s), .right(i)):
+      return .right(s.index(after: i))
+    default:
+      fatalError()
+    }
+  }
+
+  @inlinable
+  internal func index(
+    _ i: Index,
+    offsetBy distance: Int,
+    limitedBy limit: Index
+  ) -> Index? {
+    switch (self, i, limit) {
+    case let (.left(s), .left(i), .left(limit)):
+      return s.index(i, offsetBy: distance, limitedBy: limit).map { .left($0) }
+    case let (.right(s), .right(i), .right(limit)):
+      return s.index(i, offsetBy: distance, limitedBy: limit).map { .right($0) }
+    default:
+      fatalError()
+    }
+  }
+
+  @inlinable
+  internal func index(_ i: Index, offsetBy distance: Int) -> Index {
+    switch (self, i) {
+    case let (.left(s), .left(i)):
+      return .left(s.index(i, offsetBy: distance))
+    case let (.right(s), .right(i)):
+      return .right(s.index(i, offsetBy: distance))
+    default:
+      fatalError()
+    }
+  }
+
+  @inlinable
+  internal func distance(from start: Index, to end: Index) -> Int {
+    switch (self, start, end) {
+    case let (.left(s), .left(i), .left(j)):
+      return s.distance(from: i, to: j)
+    case let (.right(s), .right(i), .right(j)):
+      return s.distance(from: i, to: j)
+    default:
+      fatalError()
+    }
+  }
+}
+
+extension EitherSequence: BidirectionalCollection
+  where Left: BidirectionalCollection, Right: BidirectionalCollection
+{
+  @inlinable
+  internal func index(before i: Index) -> Index {
+    switch (self, i) {
+    case let (.left(s), .left(i)):
+      return .left(s.index(before: i))
+    case let (.right(s), .right(i)):
+      return .right(s.index(before: i))
+    default:
+      fatalError()
+    }
+  }
+}
+
+extension EitherSequence: RandomAccessCollection
+  where Left: RandomAccessCollection, Right: RandomAccessCollection {}

+ 44 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/FirstNonNil.swift

@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// firstNonNil(_:)
+//===----------------------------------------------------------------------===//
+
+extension Sequence {
+  /// Returns the first non-`nil` result obtained from applying the given
+  /// transformation to the elements of the sequence.
+  ///
+  ///     let strings = ["three", "3.14", "-5", "2"]
+  ///     if let firstInt = strings.firstNonNil({ Int($0) }) {
+  ///         print(firstInt)
+  ///         // -5
+  ///     }
+  ///
+  /// - Parameter transform: A closure that takes an element of the sequence as
+  ///   its argument and returns an optional transformed value.
+  /// - Returns: The first non-`nil` return value of the transformation, or
+  ///   `nil` if no transformation is successful.
+  ///
+  /// - Complexity: O(*n*), where *n* is the number of elements at the start of
+  ///   the sequence that result in `nil` when applying the transformation.
+  @inlinable
+  public func firstNonNil<Result>(
+    _ transform: (Element) throws -> Result?
+  ) rethrows -> Result? {
+    for value in self {
+      if let value = try transform(value) {
+        return value
+      }
+    }
+    return nil
+  }
+}

+ 311 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/FlattenCollection.swift

@@ -0,0 +1,311 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2021 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+/// A collection consisting of all the elements contained in a collection of
+/// collections.
+@usableFromInline
+internal struct FlattenCollection<Base: Collection>
+  where Base.Element: Collection
+{
+  @usableFromInline
+  internal let base: Base
+  
+  @usableFromInline
+  internal let indexOfFirstNonEmptyElement: Base.Index
+  
+  @inlinable
+  internal init(base: Base) {
+    self.base = base
+    self.indexOfFirstNonEmptyElement = base.endOfPrefix(while: { $0.isEmpty })
+  }
+}
+
+extension FlattenCollection: Collection {
+  @usableFromInline
+  internal struct Index: Comparable {
+    @usableFromInline
+    internal let outer: Base.Index
+    
+    @usableFromInline
+    internal let inner: Base.Element.Index?
+    
+    @inlinable
+    init(outer: Base.Index, inner: Base.Element.Index?) {
+      self.outer = outer
+      self.inner = inner
+    }
+    
+    @inlinable
+    internal static func < (lhs: Self, rhs: Self) -> Bool {
+      guard lhs.outer == rhs.outer else { return lhs.outer < rhs.outer }
+      return lhs.inner == nil ? false : lhs.inner! < rhs.inner!
+    }
+  }
+  
+  @inlinable
+  internal var startIndex: Index {
+    let outer = indexOfFirstNonEmptyElement
+    let inner = outer == base.endIndex ? nil : base[outer].startIndex
+    return Index(outer: outer, inner: inner)
+  }
+  
+  @inlinable
+  internal var endIndex: Index {
+    Index(outer: base.endIndex, inner: nil)
+  }
+  
+  /// Forms an index from a pair of base indices, normalizing
+  /// `(i, base2.endIndex)` to `(base1.index(after: i), base2.startIndex)` if
+  /// necessary.
+  @inlinable
+  internal func normalizeIndex(
+    outer: Base.Index,
+    inner: Base.Element.Index
+  ) -> Index {
+    if inner == base[outer].endIndex {
+      let outer = base[base.index(after: outer)...]
+        .endOfPrefix(while: { $0.isEmpty })
+      let inner = outer == base.endIndex ? nil : base[outer].startIndex
+      return Index(outer: outer, inner: inner)
+    } else {
+      return Index(outer: outer, inner: inner)
+    }
+  }
+  
+  @inlinable
+  internal func index(after index: Index) -> Index {
+    let element = base[index.outer]
+    let nextInner = element.index(after: index.inner!)
+    return normalizeIndex(outer: index.outer, inner: nextInner)
+  }
+  
+  @inlinable
+  internal subscript(position: Index) -> Base.Element.Element {
+    base[position.outer][position.inner!]
+  }
+  
+  @inlinable
+  internal func distance(from start: Index, to end: Index) -> Int {
+    guard start.outer <= end.outer
+      else { return -distance(from: end, to: start) }
+    guard let startInner = start.inner
+      else { return 0 }
+    guard start.outer != end.outer
+      else {
+        return base[start.outer].distance(from: startInner, to: end.inner!)
+      }
+    
+    let firstPart = base[start.outer][startInner...].count
+    let middlePart = base[start.outer..<end.outer].dropFirst()
+      .reduce(0, { $0 + $1.count })
+    let lastPart = end.inner.map { base[end.outer][..<$0].count } ?? 0
+    
+    return firstPart + middlePart + lastPart
+  }
+  
+  @inlinable
+  internal func index(_ index: Index, offsetBy distance: Int) -> Index {
+    guard distance != 0 else { return index }
+    
+    return distance > 0
+      ? offsetForward(index, by: distance)
+      : offsetBackward(index, by: -distance)
+  }
+  
+  @inlinable
+  internal func index(
+    _ index: Index,
+    offsetBy distance: Int,
+    limitedBy limit: Index
+  ) -> Index? {
+    guard distance != 0 else { return index }
+    
+    if distance > 0 {
+      return limit >= index
+        ? offsetForward(index, by: distance, limitedBy: limit)
+        : offsetForward(index, by: distance)
+    } else {
+      return limit <= index
+        ? offsetBackward(index, by: -distance, limitedBy: limit)
+        : offsetBackward(index, by: -distance)
+    }
+  }
+  
+  @inlinable
+  internal func offsetForward(_ i: Index, by distance: Int) -> Index {
+    guard let index = offsetForward(i, by: distance, limitedBy: endIndex)
+      else { fatalError("Index is out of bounds") }
+    return index
+  }
+  
+  @inlinable
+  internal func offsetBackward(_ i: Index, by distance: Int) -> Index {
+    guard let index = offsetBackward(i, by: distance, limitedBy: startIndex)
+      else { fatalError("Index is out of bounds") }
+    return index
+  }
+  
+  @inlinable
+  internal func offsetForward(
+    _ index: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance > 0)
+    assert(limit >= index)
+    
+    if index.outer == limit.outer {
+      if let indexInner = index.inner, let limitInner = limit.inner {
+        return base[index.outer]
+          .index(indexInner, offsetBy: distance, limitedBy: limitInner)
+          .map { inner in Index(outer: index.outer, inner: inner) }
+      } else {
+        // `index` and `limit` are both `endIndex`
+        return nil
+      }
+    }
+    
+    // `index <= limit` and `index.outer != limit.outer`, so `index != endIndex`
+    let indexInner = index.inner!
+    let element = base[index.outer]
+    
+    if let inner = element.index(
+        indexInner,
+        offsetBy: distance,
+        limitedBy: element.endIndex
+    ) {
+      return normalizeIndex(outer: index.outer, inner: inner)
+    }
+    
+    var remainder = distance - element[indexInner...].count
+    var outer = base.index(after: index.outer)
+    
+    while outer != limit.outer {
+      let element = base[outer]
+      
+      if let inner = element.index(
+          element.startIndex,
+          offsetBy: remainder,
+          limitedBy: element.endIndex
+      ) {
+        return normalizeIndex(outer: outer, inner: inner)
+      }
+      
+      remainder -= element.count
+      base.formIndex(after: &outer)
+    }
+    
+    if let limitInner = limit.inner {
+      let element = base[outer]
+      return element.index(
+        element.startIndex,
+        offsetBy: remainder,
+        limitedBy: limitInner)
+        .map { inner in Index(outer: outer, inner: inner) }
+    } else {
+      return nil
+    }
+  }
+  
+  @inlinable
+  internal func offsetBackward(
+    _ index: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance > 0)
+    assert(limit <= index)
+    
+    if index.outer == limit.outer {
+      if let indexInner = index.inner, let limitInner = limit.inner {
+        return base[index.outer]
+          .index(indexInner, offsetBy: -distance, limitedBy: limitInner)
+          .map { inner in Index(outer: index.outer, inner: inner) }
+      } else {
+        // `index` and `limit` are both `endIndex`
+        return nil
+      }
+    }
+    
+    var remainder = distance
+    
+    if let indexInner = index.inner {
+      let element = base[index.outer]
+      
+      if let inner = element.index(
+          indexInner,
+          offsetBy: -remainder,
+          limitedBy: element.startIndex
+      ) {
+        return Index(outer: index.outer, inner: inner)
+      }
+      
+      remainder -= element[..<indexInner].count
+    }
+    
+    var outer = base.index(index.outer, offsetBy: -1)
+    
+    while outer != limit.outer {
+      let element = base[outer]
+      
+      if let inner = element.index(
+          element.endIndex,
+          offsetBy: -remainder,
+          limitedBy: element.startIndex
+      ) {
+        return Index(outer: outer, inner: inner)
+      }
+      
+      remainder -= element.count
+      base.formIndex(&outer, offsetBy: -1)
+    }
+    
+    let element = base[outer]
+    return element.index(
+      element.endIndex,
+      offsetBy: -remainder,
+      limitedBy: limit.inner!
+    ).map { inner in Index(outer: outer, inner: inner) }
+  }
+}
+
+extension FlattenCollection: BidirectionalCollection
+  where Base: BidirectionalCollection, Base.Element: BidirectionalCollection
+{
+  @inlinable
+  internal func index(before index: Index) -> Index {
+    if let inner = index.inner {
+      let element = base[index.outer]
+      
+      if inner != element.startIndex {
+        let previousInner = element.index(before: inner)
+        return Index(outer: index.outer, inner: previousInner)
+      }
+    }
+    
+    let previousOuter = base[..<index.outer].lastIndex(where: { !$0.isEmpty })!
+    let element = base[previousOuter]
+    let previousInner = element.index(before: element.endIndex)
+    return Index(outer: previousOuter, inner: previousInner)
+  }
+}
+
+extension FlattenCollection: LazySequenceProtocol, LazyCollectionProtocol
+  where Base: LazySequenceProtocol, Base.Element: LazySequenceProtocol {}
+
+//===----------------------------------------------------------------------===//
+// joined()
+//===----------------------------------------------------------------------===//
+
+extension Collection where Element: Collection {
+  /// Returns the concatenation of the elements in this collection of
+  /// collections.
+  @inlinable
+  internal func joined() -> FlattenCollection<Self> {
+    FlattenCollection(base: self)
+  }
+}

+ 113 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Indexed.swift

@@ -0,0 +1,113 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+/// A collection wrapper that iterates over the indices and elements of a
+/// collection together.
+public struct IndexedCollection<Base: Collection> {
+  /// The base collection.
+  @usableFromInline
+  internal let base: Base
+  
+  @inlinable
+  internal init(base: Base) {
+    self.base = base
+  }
+}
+
+extension IndexedCollection: Collection {
+  /// The element type for an `IndexedCollection` collection.
+  public typealias Element = (index: Base.Index, element: Base.Element)
+  
+  @inlinable
+  public var startIndex: Base.Index {
+    base.startIndex
+  }
+  
+  @inlinable
+  public var endIndex: Base.Index {
+    base.endIndex
+  }
+  
+  @inlinable
+  public subscript(position: Base.Index) -> Element {
+    (index: position, element: base[position])
+  }
+  
+  @inlinable
+  public func index(after i: Base.Index) -> Base.Index {
+    base.index(after: i)
+  }
+  
+  @inlinable
+  public func index(_ i: Base.Index, offsetBy distance: Int) -> Base.Index {
+    base.index(i, offsetBy: distance)
+  }
+  
+  @inlinable
+  public func index(
+    _ i: Base.Index,
+    offsetBy distance: Int,
+    limitedBy limit: Base.Index
+  ) -> Base.Index? {
+    base.index(i, offsetBy: distance, limitedBy: limit)
+  }
+  
+  @inlinable
+  public func distance(from start: Base.Index, to end: Base.Index) -> Int {
+    base.distance(from: start, to: end)
+  }
+  
+  @inlinable
+  public var indices: Base.Indices {
+    base.indices
+  }
+}
+
+extension IndexedCollection: BidirectionalCollection
+  where Base: BidirectionalCollection
+{
+  @inlinable
+  public func index(before i: Base.Index) -> Base.Index {
+    base.index(before: i)
+  }
+}
+
+extension IndexedCollection: RandomAccessCollection
+  where Base: RandomAccessCollection {}
+
+extension IndexedCollection: LazySequenceProtocol, LazyCollectionProtocol
+  where Base: LazySequenceProtocol {}
+
+//===----------------------------------------------------------------------===//
+// indexed()
+//===----------------------------------------------------------------------===//
+
+extension Collection {
+  /// Returns a collection of pairs *(i, x)*, where *i* represents an index of
+  /// the collection, and *x* represents an element.
+  ///
+  /// This example iterates over the indices and elements of a set, building an
+  /// array consisting of indices of names with five or fewer letters.
+  ///
+  ///     let names: Set = ["Sofia", "Camilla", "Martina", "Mateo", "Nicolás"]
+  ///     var shorterIndices: [Set<String>.Index] = []
+  ///     for (i, name) in names.indexed() {
+  ///         if name.count <= 5 {
+  ///             shorterIndices.append(i)
+  ///         }
+  ///     }
+  ///
+  /// Returns: A collection of paired indices and elements of this collection.
+  @inlinable
+  public func indexed() -> IndexedCollection<Self> {
+    IndexedCollection(base: self)
+  }
+}

+ 669 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Intersperse.swift

@@ -0,0 +1,669 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// Intersperse
+//===----------------------------------------------------------------------===//
+
+/// A sequence that presents the elements of a base sequence of elements with a
+/// separator between each of those elements.
+public struct InterspersedSequence<Base: Sequence> {
+  @usableFromInline
+  internal let base: Base
+  
+  @usableFromInline
+  internal let separator: Base.Element
+  
+  @inlinable
+  internal init(base: Base, separator: Base.Element) {
+    self.base = base
+    self.separator = separator
+  }
+}
+
+extension InterspersedSequence: Sequence {
+  /// The iterator for an `InterspersedSequence` sequence.
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal enum State {
+      case start
+      case element(Base.Element)
+      case separator
+    }
+    
+    @usableFromInline
+    internal var iterator: Base.Iterator
+    
+    @usableFromInline
+    internal let separator: Base.Element
+    
+    @usableFromInline
+    internal var state = State.start
+    
+    @inlinable
+    internal init(iterator: Base.Iterator, separator: Base.Element) {
+      self.iterator = iterator
+      self.separator = separator
+    }
+
+    @inlinable
+    public mutating func next() -> Base.Element? {
+      // After the start, the state flips between element and separator. Before
+      // returning a separator, a check is made for the next element as a
+      // separator is only returned between two elements. The next element is
+      // stored to allow it to be returned in the next iteration.
+      switch state {
+      case .start:
+        state = .separator
+        return iterator.next()
+      case .separator:
+        guard let next = iterator.next() else { return nil }
+        state = .element(next)
+        return separator
+      case .element(let element):
+        state = .separator
+        return element
+      }
+    }
+  }
+
+  @inlinable
+  public func makeIterator() -> InterspersedSequence<Base>.Iterator {
+    Iterator(iterator: base.makeIterator(), separator: separator)
+  }
+}
+
+extension InterspersedSequence: Collection where Base: Collection {
+  /// A position in an `InterspersedSequence` instance.
+  public struct Index: Comparable {
+    @usableFromInline
+    internal enum Representation: Equatable {
+      case element(Base.Index)
+      case separator(next: Base.Index)
+    }
+    
+    @usableFromInline
+    internal let representation: Representation
+
+    @inlinable
+    internal init(representation: Representation) {
+      self.representation = representation
+    }
+
+    @inlinable
+    public static func < (lhs: Index, rhs: Index) -> Bool {
+      switch (lhs.representation, rhs.representation) {
+      case let (.element(li), .element(ri)),
+           let (.separator(next: li), .separator(next: ri)),
+           let (.element(li), .separator(next: ri)):
+        return li < ri
+      case let (.separator(next: li), .element(ri)):
+        return li <= ri
+      }
+    }
+    
+    @inlinable
+    internal static func element(_ index: Base.Index) -> Self {
+      Self(representation: .element(index))
+    }
+
+    @inlinable
+    internal static func separator(next: Base.Index) -> Self {
+      Self(representation: .separator(next: next))
+    }
+  }
+
+  @inlinable
+  public var startIndex: Index {
+    base.startIndex == base.endIndex ? endIndex : .element(base.startIndex)
+  }
+
+  @inlinable
+  public var endIndex: Index {
+    .separator(next: base.endIndex)
+  }
+
+  @inlinable
+  public func index(after i: Index) -> Index {
+    precondition(i != endIndex, "Can't advance past endIndex")
+    switch i.representation {
+    case let .element(index):
+      return .separator(next: base.index(after: index))
+    case let .separator(next):
+      return .element(next)
+    }
+  }
+
+  @inlinable
+  public subscript(position: Index) -> Element {
+    switch position.representation {
+    case .element(let index): return base[index]
+    case .separator: return separator
+    }
+  }
+  
+  @inlinable
+  public func distance(from start: Index, to end: Index) -> Int {
+    switch (start.representation, end.representation) {
+    case let (.element(element), .separator(next: separator)):
+      return 2 * base.distance(from: element, to: separator) - 1
+    case let (.separator(next: separator), .element(element)):
+      return 2 * base.distance(from: separator, to: element) + 1
+    case let (.element(start), .element(end)),
+         let (.separator(start), .separator(end)):
+      return 2 * base.distance(from: start, to: end)
+    }
+  }
+  
+  @inlinable
+  public func index(_ index: Index, offsetBy distance: Int) -> Index {
+    distance >= 0
+      ? offsetForward(index, by: distance)
+      : offsetBackward(index, by: -distance)
+  }
+
+  @inlinable
+  public func index(
+      _ index: Index,
+      offsetBy distance: Int,
+      limitedBy limit: Index
+    ) -> Index? {
+      if distance >= 0 {
+        return limit >= index
+          ? offsetForward(index, by: distance, limitedBy: limit)
+          : offsetForward(index, by: distance)
+      } else {
+        return limit <= index
+          ? offsetBackward(index, by: -distance, limitedBy: limit)
+          : offsetBackward(index, by: -distance)
+      }
+    }
+  
+  @inlinable
+  internal func offsetForward(_ i: Index, by distance: Int) -> Index {
+    guard let index = offsetForward(i, by: distance, limitedBy: endIndex)
+      else { fatalError("Index is out of bounds") }
+    return index
+  }
+  
+  @inlinable
+  internal func offsetBackward(_ i: Index, by distance: Int) -> Index {
+    guard let index = offsetBackward(i, by: distance, limitedBy: startIndex)
+      else { fatalError("Index is out of bounds") }
+    return index
+  }
+    
+  @inlinable
+  internal func offsetForward(
+    _ index: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance >= 0)
+    assert(limit >= index)
+    
+    switch (index.representation, limit.representation, distance.isMultiple(of: 2)) {
+    case let (.element(index), .element(limit), true),
+         let (.separator(next: index), .element(limit), false):
+      return base.index(index, offsetBy: distance / 2, limitedBy: limit)
+        .map { .element($0) }
+      
+    case let (.element(index), .element(limit), false),
+         let (.element(index), .separator(next: limit), false),
+         let (.separator(next: index), .element(limit), true),
+         let (.separator(next: index), .separator(next: limit), true):
+      return base.index(index, offsetBy: (distance + 1) / 2, limitedBy: limit)
+        .map { .separator(next: $0) }
+      
+    case let (.element(index), .separator(next: limit), true),
+         let (.separator(next: index), .separator(next: limit), false):
+      return base.index(index, offsetBy: distance / 2, limitedBy: limit)
+        .flatMap { $0 == limit ? nil : .element($0) }
+    }
+  }
+  
+  @inlinable
+  internal func offsetBackward(
+    _ index: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance >= 0)
+    assert(limit <= index)
+    
+    switch (index.representation, limit.representation, distance.isMultiple(of: 2)) {
+    case let (.element(index), .element(limit), true),
+         let (.element(index), .separator(next: limit), true),
+         let (.separator(next: index), .element(limit), false),
+         let (.separator(next: index), .separator(next: limit), false):
+      return base.index(index, offsetBy: -((distance + 1) / 2), limitedBy: limit)
+        .map { .element($0) }
+      
+    case let (.element(index), .separator(next: limit), false),
+         let (.separator(next: index), .separator(next: limit), true):
+      return base.index(index, offsetBy: -(distance / 2), limitedBy: limit)
+        .map { .separator(next: $0) }
+      
+    case let (.element(index), .element(limit), false),
+         let (.separator(next: index), .element(limit), true):
+      return base.index(index, offsetBy: -(distance / 2), limitedBy: limit)
+        .flatMap { $0 == limit ? nil : .separator(next: $0) }
+    }
+  }
+}
+
+extension InterspersedSequence: BidirectionalCollection
+  where Base: BidirectionalCollection
+{
+  @inlinable
+  public func index(before i: Index) -> Index {
+    precondition(i != startIndex, "Can't move before startIndex")
+    switch i.representation {
+    case let .element(index):
+      return .separator(next: index)
+    case let .separator(next):
+      return .element(base.index(before: next))
+    }
+  }
+}
+
+extension InterspersedSequence: RandomAccessCollection
+  where Base: RandomAccessCollection {}
+
+extension InterspersedSequence: LazySequenceProtocol
+  where Base: LazySequenceProtocol {}
+
+extension InterspersedSequence: LazyCollectionProtocol
+  where Base: LazySequenceProtocol & Collection {}
+
+//===----------------------------------------------------------------------===//
+// InterspersedMap
+//===----------------------------------------------------------------------===//
+
+
+/// A sequence over the results of applying a closure to the sequence's
+/// elements, with a separator that separates each pair of adjacent transformed
+/// values.
+@usableFromInline
+internal struct InterspersedMapSequence<Base: Sequence, Result> {
+  @usableFromInline
+  internal let base: Base
+  
+  @usableFromInline
+  internal let transform: (Base.Element) -> Result
+  
+  @usableFromInline
+  internal let separator: (Base.Element, Base.Element) -> Result
+}
+
+extension InterspersedMapSequence: Sequence {
+  @usableFromInline
+  internal struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal enum State {
+      case start
+      case element(Base.Element)
+      case separator(previous: Base.Element)
+    }
+    
+    @usableFromInline
+    internal var base: Base.Iterator
+    
+    @usableFromInline
+    internal let transform: (Base.Element) -> Result
+    
+    @usableFromInline
+    internal let separator: (Base.Element, Base.Element) -> Result
+    
+    @usableFromInline
+    internal var state = State.start
+    
+    @inlinable
+    internal init(
+      base: Base.Iterator,
+      transform: @escaping (Base.Element) -> Result,
+      separator: @escaping (Base.Element, Base.Element) -> Result
+    ) {
+      self.base = base
+      self.transform = transform
+      self.separator = separator
+    }
+
+    @inlinable
+    internal mutating func next() -> Result? {
+      switch state {
+      case .start:
+        guard let first = base.next() else { return nil }
+        state = .separator(previous: first)
+        return transform(first)
+      case .separator(let previous):
+        guard let next = base.next() else { return nil }
+        state = .element(next)
+        return separator(previous, next)
+      case .element(let element):
+        state = .separator(previous: element)
+        return transform(element)
+      }
+    }
+  }
+
+  @inlinable
+  internal func makeIterator() -> Iterator {
+    Iterator(
+      base: base.makeIterator(),
+      transform: transform,
+      separator: separator)
+  }
+}
+
+extension InterspersedMapSequence: Collection where Base: Collection {
+  @usableFromInline
+  internal struct Index: Comparable {
+    @usableFromInline
+    internal enum Representation {
+      case element(Base.Index)
+      case separator(previous: Base.Index, next: Base.Index)
+    }
+    
+    @usableFromInline
+    internal let representation: Representation
+    
+    @inlinable
+    internal init(representation: Representation) {
+      self.representation = representation
+    }
+    
+    @inlinable
+    internal static func element(_ index: Base.Index) -> Self {
+      Self(representation: .element(index))
+    }
+
+    @inlinable
+    internal static func separator(previous: Base.Index, next: Base.Index) -> Self {
+      Self(representation: .separator(previous: previous, next: next))
+    }
+    
+    @inlinable
+    internal static func == (lhs: Self, rhs: Self) -> Bool {
+      switch (lhs.representation, rhs.representation) {
+      case let (.element(lhs), .element(rhs)),
+           let (.separator(_, next: lhs), .separator(_, next: rhs)):
+        return lhs == rhs
+      case (.element, .separator), (.separator, .element):
+        return false
+      }
+    }
+    
+    @inlinable
+    internal static func < (lhs: Self, rhs: Self) -> Bool {
+      switch (lhs.representation, rhs.representation) {
+      case let (.element(lhs), .element(rhs)),
+           let (.separator(_, next: lhs), .separator(_, next: rhs)),
+           let (.element(lhs), .separator(_, next: rhs)),
+           let (.separator(previous: lhs, _), .element(rhs)):
+        return lhs < rhs
+      }
+    }
+  }
+  
+  @inlinable
+  internal var startIndex: Index {
+    base.isEmpty ? endIndex : .element(base.startIndex)
+  }
+  
+  @inlinable
+  internal var endIndex: Index {
+    .separator(previous: base.endIndex, next: base.endIndex)
+  }
+  
+  @inlinable
+  internal func index(after index: Index) -> Index {
+    switch index.representation {
+    case .element(let index):
+      let next = base.index(after: index)
+      return .separator(previous: index, next: next)
+    case .separator(_, let next):
+      return .element(next)
+    }
+  }
+  
+  @inlinable
+  internal subscript(position: Index) -> Result {
+    switch position.representation {
+    case .element(let index):
+      return transform(base[index])
+    case let .separator(previous, next):
+      return separator(base[previous], base[next])
+    }
+  }
+  
+  @inlinable
+  internal func distance(from start: Index, to end: Index) -> Int {
+    switch (start.representation, end.representation) {
+    case let (.element(lhs), .element(rhs)),
+         let (.separator(_, next: lhs), .separator(_, next: rhs)):
+      return 2 * base.distance(from: lhs, to: rhs)
+    case let (.element(lhs), .separator(_, next: rhs)):
+      return 2 * base.distance(from: lhs, to: rhs) - 1
+    case let (.separator(_, next: lhs), .element(rhs)):
+      return 2 * base.distance(from: lhs, to: rhs) + 1
+    }
+  }
+  
+  @inlinable
+  internal func index(_ index: Index, offsetBy distance: Int) -> Index {
+    guard distance != 0 else { return index }
+    
+    return distance > 0
+      ? offsetForward(index, by: distance)
+      : offsetBackward(index, by: -distance)
+  }
+  
+  @inlinable
+  internal func index(
+    _ index: Index,
+    offsetBy distance: Int,
+    limitedBy limit: Index
+  ) -> Index? {
+    guard distance != 0 else { return index }
+    
+    if distance > 0 {
+      return limit >= index
+        ? offsetForward(index, by: distance, limitedBy: limit)
+        : offsetForward(index, by: distance)
+    } else {
+      return limit <= index
+        ? offsetBackward(index, by: -distance, limitedBy: limit)
+        : offsetBackward(index, by: -distance)
+    }
+  }
+  
+  @inlinable
+  internal func offsetForward(_ i: Index, by distance: Int) -> Index {
+    guard let index = offsetForward(i, by: distance, limitedBy: endIndex)
+    else { fatalError("Index is out of bounds") }
+    return index
+  }
+  
+  @inlinable
+  internal func offsetBackward(_ i: Index, by distance: Int) -> Index {
+    guard let index = offsetBackward(i, by: distance, limitedBy: startIndex)
+    else { fatalError("Index is out of bounds") }
+    return index
+  }
+  
+  @inlinable
+  internal func offsetForward(
+    _ index: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance > 0)
+    assert(limit >= index)
+    
+    switch (index.representation, limit.representation, distance.isMultiple(of: 2)) {
+    case let (.element(index), .element(limit), true),
+         let (.separator(_, next: index), .element(limit), false):
+      return base.index(index, offsetBy: distance / 2, limitedBy: limit)
+        .map { .element($0) }
+      
+    case let (.element(index), .element(limit), false),
+         let (.element(index), .separator(_, next: limit), false),
+         let (.separator(_, next: index), .element(limit), true),
+         let (.separator(_, next: index), .separator(_, next: limit), true):
+      return base.index(index, offsetBy: (distance - 1) / 2, limitedBy: limit)
+        .flatMap {
+          guard $0 != limit else { return nil }
+          let next = base.index(after: $0)
+          return next == base.endIndex
+            ? endIndex
+            : .separator(previous: $0, next: next)
+        }
+      
+    case let (.element(index), .separator(_, next: limit), true),
+         let (.separator(_, next: index), .separator(_, next: limit), false):
+      return base.index(index, offsetBy: distance / 2, limitedBy: limit)
+        .flatMap { $0 == limit ? nil : .element($0) }
+    }
+  }
+  
+  @inlinable
+  internal func offsetBackward(
+    _ index: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance > 0)
+    assert(limit <= index)
+    
+    switch (index.representation, limit.representation, distance.isMultiple(of: 2)) {
+    case let (.element(index), .element(limit), true),
+         let (.element(index), .separator(_, next: limit), true),
+         let (.separator(_, next: index), .element(limit), false),
+         let (.separator(_, next: index), .separator(_, next: limit), false):
+      return base.index(index, offsetBy: -((distance + 1) / 2), limitedBy: limit)
+        .map { .element($0) }
+      
+    case let (.element(index), .separator(_, next: limit), false),
+         let (.separator(_, next: index), .separator(_, next: limit), true):
+      return base.index(index, offsetBy: -(distance / 2), limitedBy: limit)
+        .map { .separator(previous: base.index($0, offsetBy: -1), next: $0) }
+      
+    case let (.element(index), .element(limit), false),
+         let (.separator(_, next: index), .element(limit), true):
+      return base.index(index, offsetBy: -(distance / 2), limitedBy: limit)
+        .flatMap {
+          $0 == limit
+            ? nil
+            : .separator(previous: base.index($0, offsetBy: -1), next: $0)
+        }
+    }
+  }
+}
+
+extension InterspersedMapSequence: BidirectionalCollection
+  where Base: BidirectionalCollection
+{
+  @inlinable
+  internal func index(before index: Index) -> Index {
+    switch index.representation {
+    case .element(let index):
+      let previous = base.index(before: index)
+      return .separator(previous: previous, next: index)
+    case let .separator(previous, next):
+      let index = next == base.endIndex ? base.index(before: next) : previous
+      return .element(index)
+    }
+  }
+}
+
+extension InterspersedMapSequence.Index: Hashable
+  where Base.Index: Hashable
+{
+  @inlinable
+  internal func hash(into hasher: inout Hasher) {
+    switch representation {
+    case .element(let base):
+      hasher.combine(false)
+      hasher.combine(base)
+    case .separator(_, let next):
+      hasher.combine(true)
+      hasher.combine(next)
+    }
+  }
+}
+
+extension InterspersedMapSequence: LazySequenceProtocol {}
+extension InterspersedMapSequence: LazyCollectionProtocol
+  where Base: Collection {}
+
+//===----------------------------------------------------------------------===//
+// interspersed(with:)
+//===----------------------------------------------------------------------===//
+
+extension Sequence {
+  /// Returns a sequence containing elements of this sequence with the given
+  /// separator inserted in between each element.
+  ///
+  /// Any value of the sequence's element type can be used as the separator.
+  ///
+  /// ```
+  /// for value in [1,2,3].interspersed(with: 0) {
+  ///     print(value)
+  /// }
+  /// // 1
+  /// // 0
+  /// // 2
+  /// // 0
+  /// // 3
+  /// ```
+  ///
+  /// The following shows a String being interspersed with a Character:
+  /// ```
+  /// let result = "ABCDE".interspersed(with: "-")
+  /// print(String(result))
+  /// // "A-B-C-D-E"
+  /// ```
+  ///
+  /// - Parameter separator: Value to insert in between each of this sequence’s
+  ///   elements.
+  /// - Returns: The interspersed sequence of elements.
+  ///
+  /// - Complexity: O(1)
+  @inlinable
+  public func interspersed(
+    with separator: Element
+  ) -> InterspersedSequence<Self> {
+    InterspersedSequence(base: self, separator: separator)
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// lazy.interspersedMap(_:with:)
+//===----------------------------------------------------------------------===//
+
+extension LazySequenceProtocol {
+  /// Returns a sequence over the results of applying a closure to the
+  /// sequence's elements, with a separator that separates each pair of adjacent
+  /// transformed values.
+  ///
+  /// The transformation closure lets you intersperse a sequence using a
+  /// separator of a different type than the original's sequence's elements.
+  /// Each separator is produced by a closure that is given access to the
+  /// two elements in the original sequence right before and after it.
+  ///
+  ///     let strings = [1, 2, 2].interspersedMap(String.init,
+  ///         with: { $0 == $1 ? " == " : " != " })
+  ///     print(strings.joined()) // "1 != 2 == 2"
+  ///
+  @usableFromInline
+  internal func interspersedMap<Result>(
+    _ transform: @escaping (Element) -> Result,
+    with separator: @escaping (Element, Element) -> Result
+  ) -> InterspersedMapSequence<Elements, Result> {
+    InterspersedMapSequence(
+      base: elements,
+      transform: transform,
+      separator: separator)
+  }
+}

+ 489 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Joined.swift

@@ -0,0 +1,489 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// JoinedBySequence
+//===----------------------------------------------------------------------===//
+
+/// A sequence that presents the elements of a base sequence of sequences
+/// concatenated using a given separator.
+public struct JoinedBySequence<Base: Sequence, Separator: Sequence>
+  where Base.Element: Sequence, Base.Element.Element == Separator.Element
+{
+  @usableFromInline
+  internal typealias Inner = FlattenSequence<InterspersedSequence<
+    LazyMapSequence<Base, EitherSequence<Base.Element, Separator>>>>
+  
+  @usableFromInline
+  internal let inner: Inner
+  
+  @inlinable
+  internal init(base: Base, separator: Separator) {
+    self.inner = base.lazy
+      .map(EitherSequence.left)
+      .interspersed(with: .right(separator))
+      .joined()
+  }
+}
+
+extension JoinedBySequence: Sequence {
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal var inner: Inner.Iterator
+    
+    @inlinable
+    internal init(inner: Inner.Iterator) {
+      self.inner = inner
+    }
+    
+    @inlinable
+    public mutating func next() -> Base.Element.Element? {
+      inner.next()
+    }
+  }
+  
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(inner: inner.makeIterator())
+  }
+}
+
+extension JoinedBySequence: LazySequenceProtocol
+  where Base: LazySequenceProtocol {}
+
+//===----------------------------------------------------------------------===//
+// JoinedByClosureSequence
+//===----------------------------------------------------------------------===//
+
+/// A sequence that presents the elements of a base sequence of sequences
+/// concatenated using a given separator that depends on the sequences right
+/// before and after it.
+public struct JoinedByClosureSequence<Base: Sequence, Separator: Sequence>
+  where Base.Element: Sequence, Base.Element.Element == Separator.Element
+{
+  @usableFromInline
+  internal typealias Inner = FlattenSequence<InterspersedMapSequence<
+    Base, EitherSequence<Base.Element, Separator>>>
+  
+  @usableFromInline
+  internal let inner: Inner
+  
+  @inlinable
+  internal init(
+    base: Base,
+    separator: @escaping (Base.Element, Base.Element) -> Separator
+  ) {
+    self.inner = base.lazy
+      .interspersedMap(
+        EitherSequence.left,
+        with: { EitherSequence.right(separator($0, $1)) })
+      .joined()
+  }
+}
+
+extension JoinedByClosureSequence: Sequence {
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal var inner: Inner.Iterator
+    
+    @inlinable
+    internal init(inner: Inner.Iterator) {
+      self.inner = inner
+    }
+    
+    @inlinable
+    public mutating func next() -> Base.Element.Element? {
+      inner.next()
+    }
+  }
+  
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(inner: inner.makeIterator())
+  }
+}
+
+extension JoinedByClosureSequence: LazySequenceProtocol {}
+
+//===----------------------------------------------------------------------===//
+// JoinedByCollection
+//===----------------------------------------------------------------------===//
+
+/// A collection that presents the elements of a base collection of collections
+/// concatenated using a given separator.
+public struct JoinedByCollection<Base: Collection, Separator: Collection>
+  where Base.Element: Collection, Base.Element.Element == Separator.Element
+{
+  @usableFromInline
+  internal typealias Inner = FlattenCollection<InterspersedSequence<
+    LazyMapSequence<Base, EitherSequence<Base.Element, Separator>>>>
+  
+  @usableFromInline
+  internal let inner: Inner
+  
+  @inlinable
+  internal init(base: Base, separator: Separator) {
+    self.inner = base.lazy
+      .map(EitherSequence.left)
+      .interspersed(with: .right(separator))
+      .joined()
+  }
+}
+
+extension JoinedByCollection: Collection {
+  public struct Index: Comparable {
+    @usableFromInline
+    internal let inner: Inner.Index
+    
+    @inlinable
+    internal init(_ inner: Inner.Index) {
+      self.inner = inner
+    }
+    
+    @inlinable
+    public static func == (lhs: Self, rhs: Self) -> Bool {
+      lhs.inner == rhs.inner
+    }
+    
+    @inlinable
+    public static func < (lhs: Self, rhs: Self) -> Bool {
+      lhs.inner < rhs.inner
+    }
+  }
+  
+  @inlinable
+  public var startIndex: Index {
+    Index(inner.startIndex)
+  }
+  
+  @inlinable
+  public var endIndex: Index {
+    Index(inner.endIndex)
+  }
+  
+  @inlinable
+  public func index(after index: Index) -> Index {
+    Index(inner.index(after: index.inner))
+  }
+  
+  @inlinable
+  public subscript(position: Index) -> Base.Element.Element {
+    inner[position.inner]
+  }
+  
+  @inlinable
+  public func index(_ index: Index, offsetBy distance: Int) -> Index {
+    Index(inner.index(index.inner, offsetBy: distance))
+  }
+  
+  @inlinable
+  public func index(
+    _ index: Index,
+    offsetBy distance: Int,
+    limitedBy limit: Index
+  ) -> Index? {
+    inner.index(index.inner, offsetBy: distance, limitedBy: limit.inner)
+      .map(Index.init)
+  }
+  
+  @inlinable
+  public func distance(from start: Index, to end: Index) -> Int {
+    inner.distance(from: start.inner, to: end.inner)
+  }
+}
+
+extension JoinedByCollection: BidirectionalCollection
+  where Base: BidirectionalCollection,
+        Base.Element: BidirectionalCollection,
+        Separator: BidirectionalCollection
+{
+  @inlinable
+  public func index(before index: Index) -> Index {
+    Index(inner.index(before: index.inner))
+  }
+}
+
+extension JoinedByCollection: LazySequenceProtocol, LazyCollectionProtocol
+  where Base: LazySequenceProtocol {}
+
+//===----------------------------------------------------------------------===//
+// JoinedByClosureCollection
+//===----------------------------------------------------------------------===//
+
+/// A collection that presents the elements of a base collection of collections
+/// concatenated using a given separator that depends on the collections right
+/// before and after it.
+public struct JoinedByClosureCollection<Base: Collection, Separator: Collection>
+  where Base.Element: Collection, Base.Element.Element == Separator.Element
+{
+  @usableFromInline
+  internal typealias Inner = FlattenCollection<InterspersedMapSequence<
+    Base, EitherSequence<Base.Element, Separator>>>
+  
+  @usableFromInline
+  internal let inner: Inner
+  
+  @inlinable
+  internal init(
+    base: Base,
+    separator: @escaping (Base.Element, Base.Element) -> Separator
+  ) {
+    self.inner = base.lazy
+      .interspersedMap(
+        EitherSequence.left,
+        with: { EitherSequence.right(separator($0, $1)) })
+      .joined()
+  }
+}
+
+extension JoinedByClosureCollection: Collection {
+  public struct Index: Comparable {
+    @usableFromInline
+    internal let inner: Inner.Index
+    
+    @inlinable
+    internal init(_ inner: Inner.Index) {
+      self.inner = inner
+    }
+    
+    @inlinable
+    public static func == (lhs: Self, rhs: Self) -> Bool {
+      lhs.inner == rhs.inner
+    }
+    
+    @inlinable
+    public static func < (lhs: Self, rhs: Self) -> Bool {
+      lhs.inner < rhs.inner
+    }
+  }
+  
+  @inlinable
+  public var startIndex: Index {
+    Index(inner.startIndex)
+  }
+  
+  @inlinable
+  public var endIndex: Index {
+    Index(inner.endIndex)
+  }
+  
+  @inlinable
+  public func index(after index: Index) -> Index {
+    Index(inner.index(after: index.inner))
+  }
+  
+  @inlinable
+  public subscript(position: Index) -> Base.Element.Element {
+    inner[position.inner]
+  }
+  
+  @inlinable
+  public func index(_ index: Index, offsetBy distance: Int) -> Index {
+    Index(inner.index(index.inner, offsetBy: distance))
+  }
+  
+  @inlinable
+  public func index(
+    _ index: Index,
+    offsetBy distance: Int,
+    limitedBy limit: Index
+  ) -> Index? {
+    inner.index(index.inner, offsetBy: distance, limitedBy: limit.inner)
+      .map(Index.init)
+  }
+  
+  @inlinable
+  public func distance(from start: Index, to end: Index) -> Int {
+    inner.distance(from: start.inner, to: end.inner)
+  }
+}
+
+extension JoinedByClosureCollection: BidirectionalCollection
+  where Base: BidirectionalCollection,
+        Base.Element: BidirectionalCollection,
+        Separator: BidirectionalCollection
+{
+  @inlinable
+  public func index(before index: Index) -> Index {
+    Index(inner.index(before: index.inner))
+  }
+}
+
+extension JoinedByClosureCollection: LazyCollectionProtocol {}
+
+//===----------------------------------------------------------------------===//
+// Sequence.joined(by:)
+//===----------------------------------------------------------------------===//
+
+extension Sequence where Element: Sequence {
+  /// Returns the concatenation of the elements in this sequence of sequences,
+  /// inserting the given separator between each sequence.
+  ///
+  ///     for x in [[1, 2], [3, 4], [5, 6]].joined(by: 100) {
+  ///         print(x)
+  ///     }
+  ///     // 1, 2, 100, 3, 4, 100, 5, 6
+  @inlinable
+  public func joined(by separator: Element.Element)
+    -> JoinedBySequence<Self, CollectionOfOne<Element.Element>>
+  {
+    joined(by: CollectionOfOne(separator))
+  }
+  
+  /// Returns the concatenation of the elements in this sequence of sequences,
+  /// inserting the given separator between each sequence.
+  ///
+  ///     for x in [[1, 2], [3, 4], [5, 6]].joined(by: [100, 200]) {
+  ///         print(x)
+  ///     }
+  ///     // 1, 2, 100, 200, 3, 4, 100, 200, 5, 6
+  @inlinable
+  public func joined<Separator>(
+    by separator: Separator
+  ) -> JoinedBySequence<Self, Separator>
+    where Separator: Collection, Separator.Element == Element.Element
+  {
+    JoinedBySequence(base: self, separator: separator)
+  }
+  
+  @inlinable
+  internal func _joined(
+    by update: (inout [Element.Element], Element, Element) throws -> Void
+  ) rethrows -> [Element.Element] {
+    var iterator = makeIterator()
+    guard let first = iterator.next() else { return [] }
+    
+    var result = Array(first)
+    var previous = first
+    
+    while let next = iterator.next() {
+      try update(&result, previous, next)
+      result.append(contentsOf: next)
+      previous = next
+    }
+    
+    return result
+  }
+  
+  /// Returns the concatenation of the elements in this sequence of sequences,
+  /// inserting the separator produced by the closure between each sequence.
+  ///
+  ///     for x in [[1, 2], [3, 4], [5, 6]].joined(by: { $0.last! * $1.first! }) {
+  ///         print(x)
+  ///     }
+  ///     // 1, 2, 6, 3, 4, 20, 5, 6
+  @inlinable
+  public func joined(
+    by separator: (Element, Element) throws -> Element.Element
+  ) rethrows -> [Element.Element] {
+    try _joined(by: { $0.append(try separator($1, $2)) })
+  }
+  
+  /// Returns the concatenation of the elements in this sequence of sequences,
+  /// inserting the separator produced by the closure between each sequence.
+  ///
+  ///     for x in [[1, 2], [3, 4], [5, 6]].joined(by: { [100 * $0.last!, 100 * $1.first!] }) {
+  ///         print(x)
+  ///     }
+  ///     // 1, 2, 200, 300, 3, 4, 400, 500, 5, 6
+  @inlinable
+  public func joined<Separator>(
+    by separator: (Element, Element) throws -> Separator
+  ) rethrows -> [Element.Element]
+    where Separator: Sequence, Separator.Element == Element.Element
+  {
+    try _joined(by: { $0.append(contentsOf: try separator($1, $2)) })
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// LazySequenceProtocol.joined(by:)
+//===----------------------------------------------------------------------===//
+
+extension LazySequenceProtocol where Element: Sequence {
+  /// Returns the concatenation of the elements in this sequence of sequences,
+  /// inserting the separator produced by the closure between each sequence.
+  @inlinable
+  public func joined(
+    by separator: @escaping (Element, Element) -> Element.Element
+  ) -> JoinedByClosureSequence<Elements, CollectionOfOne<Element.Element>> {
+    joined(by: { CollectionOfOne(separator($0, $1)) })
+  }
+  
+  /// Returns the concatenation of the elements in this sequence of sequences,
+  /// inserting the separator produced by the closure between each sequence.
+  @inlinable
+  public func joined<Separator>(
+    by separator: @escaping (Element, Element) -> Separator
+  ) -> JoinedByClosureSequence<Elements, Separator> {
+    JoinedByClosureSequence(base: elements, separator: separator)
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// Collection.joined(by:)
+//===----------------------------------------------------------------------===//
+
+extension Collection where Element: Collection {
+  /// Returns the concatenation of the elements in this collection of
+  /// collections, inserting the given separator between each collection.
+  ///
+  ///     for x in [[1, 2], [3, 4], [5, 6]].joined(by: 100) {
+  ///         print(x)
+  ///     }
+  ///     // 1, 2, 100, 3, 4, 100, 5, 6
+  @inlinable
+  public func joined(by separator: Element.Element)
+    -> JoinedByCollection<Self, CollectionOfOne<Element.Element>>
+  {
+    joined(by: CollectionOfOne(separator))
+  }
+  
+  /// Returns the concatenation of the elements in this collection of
+  /// collections, inserting the given separator between each collection.
+  ///
+  ///     for x in [[1, 2], [3, 4], [5, 6]].joined(by: [100, 200]) {
+  ///         print(x)
+  ///     }
+  ///     // 1, 2, 100, 200, 3, 4, 100, 200, 5, 6
+  @inlinable
+  public func joined<Separator>(by separator: Separator)
+    -> JoinedByCollection<Self, Separator>
+  {
+    JoinedByCollection(base: self, separator: separator)
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// LazySequenceProtocol.joined(by:) where Self: Collection
+//===----------------------------------------------------------------------===//
+
+extension LazySequenceProtocol where Elements: Collection, Element: Collection {
+  /// Returns the concatenation of the elements in this collection of
+  /// collections, inserting the separator produced by the closure between each
+  /// sequence.
+  @inlinable
+  public func joined(
+    by separator: @escaping (Element, Element) -> Element.Element
+  ) -> JoinedByClosureCollection<Elements, CollectionOfOne<Element.Element>> {
+    joined(by: { CollectionOfOne(separator($0, $1)) })
+  }
+  
+  /// Returns the concatenation of the elements in this collection of
+  /// collections, inserting the separator produced by the closure between each
+  /// sequence.
+  @inlinable
+  public func joined<Separator>(
+    by separator: @escaping (Element, Element) -> Separator
+  ) -> JoinedByClosureCollection<Elements, Separator> {
+    JoinedByClosureCollection(base: elements, separator: separator)
+  }
+}

+ 484 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/MinMax.swift

@@ -0,0 +1,484 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+extension Sequence {
+  /// Implementation for min(count:areInIncreasingOrder:)
+  @inlinable
+  internal func _minImplementation(
+    count: Int,
+    sortedBy areInIncreasingOrder: (Element, Element) throws -> Bool
+  ) rethrows -> [Element] {
+    var iterator = makeIterator()
+    
+    var result: [Element] = []
+    result.reserveCapacity(count)
+    while result.count < count, let e = iterator.next() {
+      result.append(e)
+    }
+    try result.sort(by: areInIncreasingOrder)
+    
+    while let e = iterator.next() {
+      // To be part of `result`, `e` must be strictly less than `result.last`.
+      guard try areInIncreasingOrder(e, result.last!) else { continue }
+      let insertionIndex =
+        try result.partitioningIndex { try areInIncreasingOrder(e, $0) }
+      
+      assert(insertionIndex != result.endIndex)
+      result.removeLast()
+      result.insert(e, at: insertionIndex)
+    }
+
+    return result
+  }
+  
+  /// Implementation for max(count:areInIncreasingOrder:)
+  @inlinable
+  internal func _maxImplementation(
+    count: Int,
+    sortedBy areInIncreasingOrder: (Element, Element) throws -> Bool
+  ) rethrows -> [Element] {
+    var iterator = makeIterator()
+    
+    var result: [Element] = []
+    result.reserveCapacity(count)
+    while result.count < count, let e = iterator.next() {
+      result.append(e)
+    }
+    try result.sort(by: areInIncreasingOrder)
+    
+    while let e = iterator.next() {
+      // To be part of `result`, `e` must be greater/equal to `result.first`.
+      guard try !areInIncreasingOrder(e, result.first!) else { continue }
+      let insertionIndex =
+        try result.partitioningIndex { try areInIncreasingOrder(e, $0) }
+
+      assert(insertionIndex > 0)
+      // Inserting `e` and then removing the first element (or vice versa)
+      // would perform a double shift, so we manually shift down the elements
+      // before dropping `e` in.
+      var i = 1
+      while i < insertionIndex {
+        result[i - 1] = result[i]
+        i += 1
+      }
+      result[insertionIndex - 1] = e
+    }
+    
+    return result
+  }
+  
+  /// Returns the smallest elements of this sequence, as sorted by the given
+  /// predicate.
+  ///
+  /// This example partially sorts an array of integers to retrieve its three
+  /// smallest values:
+  ///
+  ///     let numbers = [7, 1, 6, 2, 8, 3, 9]
+  ///     let smallestThree = numbers.min(count: 3, sortedBy: <)
+  ///     // [1, 2, 3]
+  ///
+  /// If you need to sort a sequence but only need to access its smallest
+  /// elements, using this method can give you a performance boost over sorting
+  /// the entire sequence. The order of equal elements is guaranteed to be
+  /// preserved.
+  ///
+  /// - Parameters:
+  ///   - count: The number of elements to return. If `count` is greater than
+  ///     the number of elements in this sequence, all of the sequence's
+  ///     elements are returned.
+  ///   - areInIncreasingOrder: A predicate that returns `true` if its
+  ///     first argument should be ordered before its second argument;
+  ///     otherwise, `false`.
+  /// - Returns: An array of the smallest `count` elements of this sequence,
+  ///   sorted according to `areInIncreasingOrder`.
+  ///
+  /// - Complexity: O(*k* log *k* + *nk*), where *n* is the length of the
+  ///   sequence and *k* is `count`.
+  @inlinable
+  public func min(
+    count: Int,
+    sortedBy areInIncreasingOrder: (Element, Element) throws -> Bool
+  ) rethrows -> [Element] {
+    precondition(count >= 0, """
+      Cannot find a minimum with a negative count of elements!
+      """
+    )
+
+    // Do nothing if we're prefixing nothing.
+    guard count > 0 else {
+      return []
+    }
+
+    return try _minImplementation(count: count, sortedBy: areInIncreasingOrder)
+  }
+
+  /// Returns the largest elements of this sequence, as sorted by the given
+  /// predicate.
+  ///
+  /// This example partially sorts an array of integers to retrieve its three
+  /// largest values:
+  ///
+  ///     let numbers = [7, 1, 6, 2, 8, 3, 9]
+  ///     let smallestThree = numbers.max(count: 3, sortedBy: <)
+  ///     // [7, 8, 9]
+  ///
+  /// If you need to sort a sequence but only need to access its largest
+  /// elements, using this method can give you a performance boost over sorting
+  /// the entire sequence. The order of equal elements is guaranteed to be
+  /// preserved.
+  ///
+  /// - Parameters:
+  ///   - count: The number of elements to return. If `count` is greater than
+  ///     the number of elements in this sequence, all of the sequence's
+  ///     elements are returned.
+  ///   - areInIncreasingOrder: A predicate that returns `true` if its
+  ///     first argument should be ordered before its second argument;
+  ///     otherwise, `false`.
+  /// - Returns: An array of the largest `count` elements of this sequence,
+  ///   sorted according to `areInIncreasingOrder`.
+  ///
+  /// - Complexity: O(*k* log *k* + *nk*), where *n* is the length of the
+  ///   sequence and *k* is `count`.
+  @inlinable
+  public func max(
+    count: Int,
+    sortedBy areInIncreasingOrder: (Element, Element) throws -> Bool
+  ) rethrows -> [Element] {
+    precondition(count >= 0, """
+      Cannot find a maximum with a negative count of elements!
+      """
+    )
+
+    // Do nothing if we're suffixing nothing.
+    guard count > 0 else {
+      return []
+    }
+
+    return try _maxImplementation(count: count, sortedBy: areInIncreasingOrder)
+  }
+}
+
+extension Sequence where Element: Comparable {
+  /// Returns the smallest elements of this sequence.
+  ///
+  /// This example partially sorts an array of integers to retrieve its three
+  /// smallest values:
+  ///
+  ///     let numbers = [7, 1, 6, 2, 8, 3, 9]
+  ///     let smallestThree = numbers.min(count: 3)
+  ///     // [1, 2, 3]
+  ///
+  /// If you need to sort a sequence but only need to access its smallest
+  /// elements, using this method can give you a performance boost over sorting
+  /// the entire sequence. The order of equal elements is guaranteed to be
+  /// preserved.
+  ///
+  /// - Parameter count: The number of elements to return. If `count` is greater
+  ///   than the number of elements in this sequence, all of the sequence's
+  ///   elements are returned.
+  /// - Returns: An array of the smallest `count` elements of this sequence.
+  ///
+  /// - Complexity: O(*k* log *k* + *nk*), where *n* is the length of the
+  ///   sequence and *k* is `count`.
+  @inlinable
+  public func min(count: Int) -> [Element] {
+    min(count: count, sortedBy: <)
+  }
+
+  /// Returns the largest elements of this sequence.
+  ///
+  /// This example partially sorts an array of integers to retrieve its three
+  /// largest values:
+  ///
+  ///     let numbers = [7, 1, 6, 2, 8, 3, 9]
+  ///     let smallestThree = numbers.max(count: 3)
+  ///     // [7, 8, 9]
+  ///
+  /// If you need to sort a sequence but only need to access its largest
+  /// elements, using this method can give you a performance boost over sorting
+  /// the entire sequence. The order of equal elements is guaranteed to be
+  /// preserved.
+  ///
+  /// - Parameter count: The number of elements to return. If `count` is greater
+  ///   than the number of elements in this sequence, all of the sequence's
+  ///   elements are returned.
+  /// - Returns: An array of the largest `count` elements of this sequence.
+  ///
+  /// - Complexity: O(*k* log *k* + *nk*), where *n* is the length of the
+  ///   sequence and *k* is `count`.
+  @inlinable
+  public func max(count: Int) -> [Element] {
+    max(count: count, sortedBy: <)
+  }
+}
+
+extension Collection {
+  /// Returns the smallest elements of this collection, as sorted by the given
+  /// predicate.
+  ///
+  /// This example partially sorts an array of integers to retrieve its three
+  /// smallest values:
+  ///
+  ///     let numbers = [7, 1, 6, 2, 8, 3, 9]
+  ///     let smallestThree = numbers.min(count: 3, sortedBy: <)
+  ///     // [1, 2, 3]
+  ///
+  /// If you need to sort a collection but only need to access its smallest
+  /// elements, using this method can give you a performance boost over sorting
+  /// the entire collection. The order of equal elements is guaranteed to be
+  /// preserved.
+  ///
+  /// - Parameters:
+  ///   - count: The number of elements to return. If `count` is greater than
+  ///     the number of elements in this collection, all of the collection's
+  ///     elements are returned.
+  ///   - areInIncreasingOrder: A predicate that returns `true` if its
+  ///     first argument should be ordered before its second argument;
+  ///     otherwise, `false`.
+  /// - Returns: An array of the smallest `count` elements of this collection,
+  ///   sorted according to `areInIncreasingOrder`.
+  ///
+  /// - Complexity: O(*k* log *k* + *nk*), where *n* is the length of the
+  ///   collection and *k* is `count`.
+  @inlinable
+  public func min(
+    count: Int,
+    sortedBy areInIncreasingOrder: (Element, Element) throws -> Bool
+  ) rethrows -> [Element] {
+    precondition(count >= 0, """
+      Cannot find a minimum with a negative count of elements!
+      """
+    )
+
+    // Do nothing if we're prefixing nothing.
+    guard count > 0 else {
+      return []
+    }
+
+    // Make sure we are within bounds.
+    let prefixCount = Swift.min(count, self.count)
+
+    // If we're attempting to prefix more than 10% of the collection, it's
+    // faster to sort everything.
+    guard prefixCount < (self.count / 10) else {
+      return Array(try sorted(by: areInIncreasingOrder).prefix(prefixCount))
+    }
+    
+    return try _minImplementation(count: count, sortedBy: areInIncreasingOrder)
+  }
+
+  /// Returns the largest elements of this collection, as sorted by the given
+  /// predicate.
+  ///
+  /// This example partially sorts an array of integers to retrieve its three
+  /// largest values:
+  ///
+  ///     let numbers = [7, 1, 6, 2, 8, 3, 9]
+  ///     let smallestThree = numbers.max(count: 3, sortedBy: <)
+  ///     // [7, 8, 9]
+  ///
+  /// If you need to sort a collection but only need to access its largest
+  /// elements, using this method can give you a performance boost over sorting
+  /// the entire collection. The order of equal elements is guaranteed to be
+  /// preserved.
+  ///
+  /// - Parameters:
+  ///   - count: The number of elements to return. If `count` is greater than
+  ///     the number of elements in this collection, all of the collection's
+  ///     elements are returned.
+  ///   - areInIncreasingOrder: A predicate that returns `true` if its
+  ///     first argument should be ordered before its second argument;
+  ///     otherwise, `false`.
+  /// - Returns: An array of the largest `count` elements of this collection,
+  ///   sorted according to `areInIncreasingOrder`.
+  ///
+  /// - Complexity: O(*k* log *k* + *nk*), where *n* is the length of the
+  ///   collection and *k* is `count`.
+  @inlinable
+  public func max(
+    count: Int,
+    sortedBy areInIncreasingOrder: (Element, Element) throws -> Bool
+  ) rethrows -> [Element] {
+    precondition(count >= 0, """
+      Cannot find a maximum with a negative count of elements!
+      """
+    )
+
+    // Do nothing if we're suffixing nothing.
+    guard count > 0 else {
+      return []
+    }
+
+    // Make sure we are within bounds.
+    let suffixCount = Swift.min(count, self.count)
+
+    // If we're attempting to prefix more than 10% of the collection, it's
+    // faster to sort everything.
+    guard suffixCount < (self.count / 10) else {
+      return Array(try sorted(by: areInIncreasingOrder).suffix(suffixCount))
+    }
+
+    return try _maxImplementation(count: count, sortedBy: areInIncreasingOrder)
+  }
+}
+
+extension Collection where Element: Comparable {
+  /// Returns the smallest elements of this collection.
+  ///
+  /// This example partially sorts an array of integers to retrieve its three
+  /// smallest values:
+  ///
+  ///     let numbers = [7, 1, 6, 2, 8, 3, 9]
+  ///     let smallestThree = numbers.min(count: 3)
+  ///     // [1, 2, 3]
+  ///
+  /// If you need to sort a collection but only need to access its smallest
+  /// elements, using this method can give you a performance boost over sorting
+  /// the entire collection. The order of equal elements is guaranteed to be
+  /// preserved.
+  ///
+  /// - Parameter count: The number of elements to return. If `count` is greater
+  ///   than the number of elements in this collection, all of the collection's
+  ///   elements are returned.
+  /// - Returns: An array of the smallest `count` elements of this collection.
+  ///
+  /// - Complexity: O(*k* log *k* + *nk*), where *n* is the length of the
+  ///   collection and *k* is `count`.
+  @inlinable
+  public func min(count: Int) -> [Element] {
+    min(count: count, sortedBy: <)
+  }
+
+  /// Returns the largest elements of this collection.
+  ///
+  /// This example partially sorts an array of integers to retrieve its three
+  /// largest values:
+  ///
+  ///     let numbers = [7, 1, 6, 2, 8, 3, 9]
+  ///     let smallestThree = numbers.max(count: 3)
+  ///     // [7, 8, 9]
+  ///
+  /// If you need to sort a collection but only need to access its largest
+  /// elements, using this method can give you a performance boost over sorting
+  /// the entire collection. The order of equal elements is guaranteed to be
+  /// preserved.
+  ///
+  /// - Parameter count: The number of elements to return. If `count` is greater
+  ///   than the number of elements in this collection, all of the collection's
+  ///   elements are returned.
+  /// - Returns: An array of the largest `count` elements of this collection.
+  ///
+  /// - Complexity: O(*k* log *k* + *nk*), where *n* is the length of the
+  ///   collection and *k* is `count`.
+  @inlinable
+  public func max(count: Int) -> [Element] {
+    max(count: count, sortedBy: <)
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// Simultaneous minimum and maximum evaluation
+//===----------------------------------------------------------------------===//
+
+extension Sequence {
+  /// Returns both the minimum and maximum elements in the sequence, using the
+  /// given predicate as the comparison between elements.
+  ///
+  /// The predicate must be a *strict weak ordering* over the elements. That is,
+  /// for any elements `a`, `b`, and `c`, the following conditions must hold:
+  ///
+  /// - `areInIncreasingOrder(a, a)` is always `false`. (Irreflexivity)
+  /// - If `areInIncreasingOrder(a, b)` and `areInIncreasingOrder(b, c)` are
+  ///   both `true`, then `areInIncreasingOrder(a, c)` is also
+  ///   `true`. (Transitive comparability)
+  /// - Two elements are *incomparable* if neither is ordered before the other
+  ///   according to the predicate. If `a` and `b` are incomparable, and `b`
+  ///   and `c` are incomparable, then `a` and `c` are also incomparable.
+  ///   (Transitive incomparability)
+  ///
+  /// This example shows how to use the `minAndMax(by:)` method on a dictionary
+  /// to find the key-value pair with the lowest value and the pair with the
+  /// highest value.
+  ///
+  ///     let hues = ["Heliotrope": 296, "Coral": 16, "Aquamarine": 156]
+  ///     if let extremeHues = hues.minAndMax(by: {$0.value < $1.value}) {
+  ///         print(extremeHues.min, extremeHues.max)
+  ///     } else {
+  ///         print("There are no hues")
+  ///     }
+  ///     // Prints: "(key: "Coral", value: 16) (key: "Heliotrope", value: 296)"
+  ///
+  /// - Precondition: The sequence is finite.
+  ///
+  /// - Parameter areInIncreasingOrder: A predicate that returns `true` if its
+  ///   first argument should be ordered before its second argument; otherwise,
+  ///   `false`.
+  /// - Returns: A tuple with the sequence's minimum element, followed by its
+  ///   maximum element. If the sequence provides multiple qualifying minimum
+  ///   elements, the first equivalent element is returned; of multiple maximum
+  ///   elements, the last is returned. If the sequence has no elements, the
+  ///   method returns `nil`.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the sequence.
+  @inlinable
+  public func minAndMax(
+    by areInIncreasingOrder: (Element, Element) throws -> Bool
+  ) rethrows -> (min: Element, max: Element)? {
+    // Check short sequences.
+    var iterator = makeIterator()
+    guard var lowest = iterator.next() else { return nil }
+    guard var highest = iterator.next() else { return (lowest, lowest) }
+
+    // Confirm the initial bounds.
+    if try areInIncreasingOrder(highest, lowest) { swap(&lowest, &highest) }
+
+    // Read the elements in pairwise.  Structuring the comparisons around this
+    // is actually faster than loops based on extracting and testing elements
+    // one-at-a-time.
+    while var low = iterator.next() {
+      var high = iterator.next() ?? low
+      if try areInIncreasingOrder(high, low) { swap(&low, &high) }
+      if try areInIncreasingOrder(low, lowest) { lowest = low }
+      if try !areInIncreasingOrder(high, highest) { highest = high }
+    }
+
+    return (lowest, highest)
+  }
+}
+
+extension Sequence where Element: Comparable {
+  /// Returns both the minimum and maximum elements in the sequence.
+  ///
+  /// This example finds the smallest and largest values in an array of height
+  /// measurements.
+  ///
+  ///     let heights = [67.5, 65.7, 64.3, 61.1, 58.5, 60.3, 64.9]
+  ///     if let (lowestHeight, greatestHeight) = heights.minAndMax() {
+  ///         print(lowestHeight, greatestHeight)
+  ///     } else {
+  ///         print("The list of heights is empty")
+  ///     }
+  ///     // Prints: "58.5 67.5"
+  ///
+  /// - Precondition: The sequence is finite.
+  ///
+  /// - Returns: A tuple with the sequence's minimum element, followed by its
+  ///   maximum element. If the sequence provides multiple qualifying minimum
+  ///   elements, the first equivalent element is returned; of multiple maximum
+  ///   elements, the last is returned. If the sequence has no elements, the
+  ///   method returns `nil`.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the sequence.
+  @inlinable
+  public func minAndMax() -> (min: Element, max: Element)? {
+    minAndMax(by: <)
+  }
+}

+ 206 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Partition.swift

@@ -0,0 +1,206 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// stablePartition(by:)
+//===----------------------------------------------------------------------===//
+
+extension MutableCollection {
+  /// Moves all elements satisfying `belongsInSecondPartition` into a suffix of
+  /// the collection, preserving their relative order, and returns the start of
+  /// the resulting suffix.
+  ///
+  /// - Complexity: O(*n* log *n*), where *n* is the number of elements.
+  /// - Precondition:
+  ///   `n == distance(from: range.lowerBound, to: range.upperBound)`
+  @inlinable
+  internal mutating func stablePartition(
+    count n: Int,
+    subrange: Range<Index>,
+    by belongsInSecondPartition: (Element) throws -> Bool
+  ) rethrows -> Index {
+    if n == 0 { return subrange.lowerBound }
+    if n == 1 {
+      return try belongsInSecondPartition(self[subrange.lowerBound])
+        ? subrange.lowerBound
+        : subrange.upperBound
+    }
+    
+    let h = n / 2, i = index(subrange.lowerBound, offsetBy: h)
+    let j = try stablePartition(
+      count: h,
+      subrange: subrange.lowerBound..<i,
+      by: belongsInSecondPartition)
+    let k = try stablePartition(
+      count: n - h,
+      subrange: i..<subrange.upperBound,
+      by: belongsInSecondPartition)
+    return rotate(subrange: j..<k, toStartAt: i)
+  }
+  
+  /// Moves all elements satisfying the given predicate into a suffix of the
+  /// given range, preserving the relative order of the elements in both
+  /// partitions, and returns the start of the resulting suffix.
+  ///
+  /// - Parameters:
+  ///   - subrange: The range of elements within this collection to partition.
+  ///   - belongsInSecondPartition: A predicate used to partition the
+  ///     collection. All elements satisfying this predicate are ordered after
+  ///     all elements not satisfying it.
+  ///
+  /// - Complexity: O(*n* log *n*), where *n* is the length of this collection.
+  @inlinable
+  public mutating func stablePartition(
+    subrange: Range<Index>,
+    by belongsInSecondPartition: (Element) throws-> Bool
+  ) rethrows -> Index {
+    try stablePartition(
+      count: distance(from: subrange.lowerBound, to: subrange.upperBound),
+      subrange: subrange,
+      by: belongsInSecondPartition)
+  }
+  
+  /// Moves all elements satisfying the given predicate into a suffix of this
+  /// collection, preserving the relative order of the elements in both
+  /// partitions, and returns the start of the resulting suffix.
+  ///
+  /// - Parameter belongsInSecondPartition: A predicate used to partition the
+  ///   collection. All elements satisfying this predicate are ordered after
+  ///   all elements not satisfying it.
+  ///
+  /// - Complexity: O(*n* log *n*), where *n* is the length of this collection.
+  @inlinable
+  public mutating func stablePartition(
+    by belongsInSecondPartition: (Element) throws-> Bool
+  ) rethrows -> Index {
+    try stablePartition(
+      subrange: startIndex..<endIndex,
+      by: belongsInSecondPartition)
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// partition(by:)
+//===----------------------------------------------------------------------===//
+
+extension MutableCollection {
+  /// Moves all elements satisfying `isSuffixElement` into a suffix of the
+  /// collection, returning the start position of the resulting suffix.
+  ///
+  /// - Complexity: O(*n*) where n is the length of the collection.
+  @inlinable
+  public mutating func partition(
+    subrange: Range<Index>,
+    by belongsInSecondPartition: (Element) throws -> Bool
+  ) rethrows -> Index {
+    // This version of `partition(subrange:)` is half stable; the elements in
+    // the first partition retain their original relative order.
+    guard var i = try self[subrange].firstIndex(where: belongsInSecondPartition)
+      else { return subrange.upperBound }
+    
+    var j = index(after: i)
+    while j != subrange.upperBound {
+      if try !belongsInSecondPartition(self[j]) {
+        swapAt(i, j)
+        formIndex(after: &i)
+      }
+      formIndex(after: &j)
+    }
+    
+    return i
+  }
+}
+
+extension MutableCollection where Self: BidirectionalCollection {
+  /// Moves all elements satisfying `isSuffixElement` into a suffix of the
+  /// collection, returning the start position of the resulting suffix.
+  ///
+  /// - Complexity: O(*n*) where n is the length of the collection.
+  @inlinable
+  public mutating func partition(
+    subrange: Range<Index>,
+    by belongsInSecondPartition: (Element) throws -> Bool
+  ) rethrows -> Index {
+    var lo = subrange.lowerBound
+    var hi = subrange.upperBound
+
+    // 'Loop' invariants (at start of Loop, all are true):
+    // * lo < hi
+    // * predicate(self[i]) == false, for i in startIndex ..< lo
+    // * predicate(self[i]) == true, for i in hi ..< endIndex
+
+    Loop: while true {
+      FindLo: do {
+        while lo < hi {
+          if try belongsInSecondPartition(self[lo]) { break FindLo }
+          formIndex(after: &lo)
+        }
+        break Loop
+      }
+
+      FindHi: do {
+        formIndex(before: &hi)
+        while lo < hi {
+          if try !belongsInSecondPartition(self[hi]) { break FindHi }
+          formIndex(before: &hi)
+        }
+        break Loop
+      }
+
+      swapAt(lo, hi)
+      formIndex(after: &lo)
+    }
+
+    return lo
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// partitioningIndex(where:)
+//===----------------------------------------------------------------------===//
+
+extension Collection {
+  /// Returns the index of the first element in the collection that matches
+  /// the predicate.
+  ///
+  /// The collection must already be partitioned according to the predicate.
+  /// That is, there should be an index `i` where for every element in
+  /// `collection[..<i]` the predicate is `false`, and for every element in
+  /// `collection[i...]` the predicate is `true`.
+  ///
+  /// - Parameter belongsInSecondPartition: A predicate that partitions the
+  ///   collection.
+  /// - Returns: The index of the first element in the collection for which
+  ///   `predicate` returns `true`.
+  ///
+  /// - Complexity: O(log *n*), where *n* is the length of this collection if
+  ///   the collection conforms to `RandomAccessCollection`, otherwise O(*n*).
+  @inlinable
+  public func partitioningIndex(
+    where belongsInSecondPartition: (Element) throws -> Bool
+  ) rethrows -> Index {
+    var n = count
+    var l = startIndex
+    
+    while n > 0 {
+      let half = n / 2
+      let mid = index(l, offsetBy: half)
+      if try belongsInSecondPartition(self[mid]) {
+        n = half
+      } else {
+        l = index(after: mid)
+        n -= half + 1
+      }
+    }
+    return l
+  }
+}
+

+ 592 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Permutations.swift

@@ -0,0 +1,592 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// nextPermutation()
+//===----------------------------------------------------------------------===//
+
+extension MutableCollection
+  where Self: BidirectionalCollection, Element: Comparable
+{
+  /// Permutes this collection's elements through all the lexical orderings.
+  ///
+  /// Call `nextPermutation()` repeatedly starting with the collection in sorted
+  /// order. When the full cycle of all permutations has been completed, the
+  /// collection will be back in sorted order and this method will return
+  /// `false`.
+  ///
+  /// - Returns: A Boolean value indicating whether the collection still has
+  ///   remaining permutations. When this method returns `false`, the collection
+  ///   is in ascending order according to `areInIncreasingOrder`.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the collection.
+  @inlinable
+  internal mutating func nextPermutation(upperBound: Index? = nil) -> Bool {
+    // Ensure we have > 1 element in the collection.
+    guard !isEmpty else { return false }
+    var i = index(before: endIndex)
+    if i == startIndex { return false }
+    
+    let upperBound = upperBound ?? endIndex
+    
+    while true {
+      let ip1 = i
+      formIndex(before: &i)
+      
+      // Find the last ascending pair (ie. ..., a, b, ... where a < b)
+      if self[i] < self[ip1] {
+        // Find the last element greater than self[i]
+        // This is _always_ at most `ip1` due to if statement above
+        let j = lastIndex(where: { self[i] < $0 })!
+        
+        // At this point we have something like this:
+        //    0, 1, 4, 3, 2
+        //       ^        ^
+        //       i        j
+        swapAt(i, j)
+        self.reverse(subrange: ip1 ..< endIndex)
+        
+        // Only return if we've made a change within ..<upperBound region
+        if i < upperBound {
+          return true
+        } else {
+          i = index(before: endIndex)
+          continue
+        }
+      }
+      
+      if i == startIndex {
+        self.reverse()
+        return false
+      }
+    }
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// struct Permutations<Base>
+//===----------------------------------------------------------------------===//
+
+/// A sequence of all the permutations of a collection's elements.
+public struct PermutationsSequence<Base: Collection> {
+  /// The base collection to iterate over for permutations.
+  @usableFromInline
+  internal let base: Base
+  
+  @usableFromInline
+  internal let baseCount: Int
+  
+  /// The range of accepted sizes of permutations.
+  ///
+  /// - Note: This may be empty if the attempted range entirely exceeds the
+  /// bounds of the size of the `base` collection.
+  @usableFromInline
+  internal let kRange: Range<Int>
+  
+  /// Initializes a `PermutationsSequence` for all permutations of `base` of
+  /// size `k`.
+  ///
+  /// - Parameters:
+  ///   - base: The collection to iterate over for permutations
+  ///   - k: The expected size of each permutation, or `nil` (default) to
+  ///   iterate over all permutations of the same size as the base collection.
+  @inlinable
+  internal init(_ base: Base, k: Int? = nil) {
+    let kRange: ClosedRange<Int>?
+    if let countToChoose = k {
+      kRange = countToChoose ... countToChoose
+    } else {
+      kRange = nil
+    }
+    self.init(base, kRange: kRange)
+  }
+  
+  /// Initializes a `PermutationsSequence` for all combinations of `base` of
+  /// sizes within a given range.
+  ///
+  /// - Parameters:
+  ///   - base: The collection to iterate over for permutations.
+  ///   - kRange: The range of accepted sizes of permutations, or `nil` to
+  ///   iterate over all permutations of the same size as the base collection.
+  @inlinable
+  internal init<R: RangeExpression>(
+    _ base: Base, kRange: R?
+  ) where R.Bound == Int {
+    self.base = base
+    let baseCount = base.count
+    self.baseCount = baseCount
+    let upperBound = baseCount + 1
+    self.kRange = kRange?.relative(to: 0 ..< .max)
+      .clamped(to: 0 ..< upperBound) ??
+      baseCount ..< upperBound
+  }
+  
+  /// The total number of permutations.
+  @inlinable
+  public var count: Int {
+    kRange.map {
+      stride(from: baseCount, to: baseCount - $0, by: -1).reduce(1, *)
+    }.reduce(0, +)
+  }
+}
+
+extension PermutationsSequence: Sequence {
+  /// The iterator for a `PermutationsSequence` instance.
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal let base: Base
+    
+    @usableFromInline
+    internal let baseCount: Int
+    
+    /// The current range of accepted sizes of permutations.
+    /// - Note: The range is contracted until empty while iterating over
+    /// permutations of different sizes. When the range is empty, iteration is
+    /// finished.
+    @usableFromInline
+    internal var kRange: Range<Int>
+    
+    /// Whether or not iteration is finished (`kRange` is empty)
+    @inlinable
+    internal var isFinished: Bool {
+      return kRange.isEmpty
+    }
+    
+    @usableFromInline
+    internal var indexes: [Base.Index]
+    
+    @inlinable
+    internal init(_ permutations: PermutationsSequence) {
+      self.base = permutations.base
+      self.baseCount = permutations.baseCount
+      self.kRange = permutations.kRange
+      self.indexes = Array(permutations.base.indices)
+    }
+    
+    /// Advances the `indexes` array such that the first `countToChoose`
+    /// elements contain the next lexicographic ordering of elements.
+    ///
+    /// Uses the SEP(n,k) algorithm, as described in:
+    /// https://alistairisrael.wordpress.com/2009/09/22/simple-efficient-pnk-algorithm/
+    ///
+    /// - Returns: A Boolean value indicating whether `indexes` still has
+    ///   remaining permutations. When this method returns `false`, `indexes`
+    ///   is in ascending order.
+    ///
+    /// - Complexity: O(*n*), where *n* is the length of the collection.
+    @inlinable
+    internal mutating func nextState() -> Bool {
+      let countToChoose = self.kRange.lowerBound
+      let edge = countToChoose - 1
+      
+      // Find first index greater than the one at `edge`.
+      if let i = indexes[countToChoose...].firstIndex(where: { indexes[edge] < $0 }) {
+        indexes.swapAt(edge, i)
+      } else {
+        indexes.reverse(subrange: countToChoose ..< indexes.endIndex)
+        
+        // Find last increasing pair below `edge`.
+        // TODO: This could be indexes[..<edge].adjacentPairs().lastIndex(where: ...)
+        var lastAscent = edge - 1
+        while (lastAscent >= 0 && indexes[lastAscent] >= indexes[lastAscent + 1]) {
+          lastAscent -= 1
+        }
+        if lastAscent < 0 {
+          return false
+        }
+        
+        // Find rightmost index less than that at `lastAscent`.
+        if let i = indexes[lastAscent...].lastIndex(where: { indexes[lastAscent] < $0 }) {
+          indexes.swapAt(lastAscent, i)
+        }
+        indexes.reverse(subrange: (lastAscent + 1) ..< indexes.endIndex)
+      }
+      
+      return true
+    }
+    
+    @inlinable
+    public mutating func next() -> [Base.Element]? {
+      guard !isFinished else { return nil }
+      
+      /// Advances `kRange` by incrementing its `lowerBound` until the range is
+      /// empty, when iteration is finished.
+      func advanceKRange() {
+        kRange.removeFirst()
+        indexes = Array(base.indices)
+      }
+      
+      let countToChoose = self.kRange.lowerBound
+      if countToChoose == 0 {
+        defer {
+          advanceKRange()
+        }
+        return []
+      }
+      
+      let permutesFullCollection = (countToChoose == baseCount)
+      if permutesFullCollection {
+        // If we're permuting the full collection, each iteration is just a
+        // call to `nextPermutation` on `indexes`.
+        defer {
+          let hasMorePermutations = indexes.nextPermutation()
+          if !hasMorePermutations {
+            advanceKRange()
+          }
+        }
+        return indexes.map { base[$0] }
+      } else {
+        // Otherwise, return the items at the first `countToChoose` indices and
+        // advance the state.
+        defer {
+          let hasMorePermutations = nextState()
+          if !hasMorePermutations {
+            advanceKRange()
+          }
+        }
+        return indexes.prefix(countToChoose).map { base[$0] }
+      }
+    }
+  }
+  
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(self)
+  }
+}
+
+extension PermutationsSequence: LazySequenceProtocol
+  where Base: LazySequenceProtocol {}
+
+//===----------------------------------------------------------------------===//
+// permutations(ofCount:)
+//===----------------------------------------------------------------------===//
+
+extension Collection {
+  /// Returns a collection of the permutations of this collection with lengths
+  /// in the specified range.
+  ///
+  /// This example prints the different permutations of one to two elements from
+  /// an array of three names:
+  ///
+  ///     let names = ["Alex", "Celeste", "Davide"]
+  ///     for perm in names.permutations(ofCount: 1...2) {
+  ///         print(perm.joined(separator: ", "))
+  ///     }
+  ///     // Alex
+  ///     // Celeste
+  ///     // Davide
+  ///     // Alex, Celeste
+  ///     // Alex, Davide
+  ///     // Celeste, Alex
+  ///     // Celeste, Davide
+  ///     // Davide, Alex
+  ///     // Davide, Celeste
+  ///
+  /// This example prints _all_ the permutations (including an empty array) from
+  /// an array of numbers:
+  ///
+  ///     let numbers = [10, 20, 30]
+  ///     for perm in numbers.permutations(ofCount: 0...) {
+  ///         print(perm)
+  ///     }
+  ///     // []
+  ///     // [10]
+  ///     // [20]
+  ///     // [30]
+  ///     // [10, 20]
+  ///     // [10, 30]
+  ///     // [20, 10]
+  ///     // [20, 30]
+  ///     // [30, 10]
+  ///     // [30, 20]
+  ///     // [10, 20, 30]
+  ///     // [10, 30, 20]
+  ///     // [20, 10, 30]
+  ///     // [20, 30, 10]
+  ///     // [30, 10, 20]
+  ///     // [30, 20, 10]
+  ///
+  /// The returned permutations are in ascending order by length, and then
+  /// lexicographically within each group of the same length.
+  ///
+  /// - Parameter kRange: A range of the number of elements to include in each
+  ///   permutation. `kRange` can be any integer range expression, and is
+  ///   clamped to the number of elements in this collection. Passing a range
+  ///   covering sizes greater than the number of elements in this collection
+  ///   results in an empty sequence.
+  ///
+  /// - Complexity: O(1) for random-access base collections. O(*n*) where *n*
+  ///   is the number of elements in the base collection, since
+  ///   `PermutationsSequence` accesses the `count` of the base collection.
+  @inlinable
+  public func permutations<R: RangeExpression>(
+    ofCount kRange: R
+  ) -> PermutationsSequence<Self> where R.Bound == Int {
+    PermutationsSequence(self, kRange: kRange)
+  }
+  
+  /// Returns a collection of the permutations of this collection of the
+  /// specified length.
+  ///
+  /// This example prints the different permutations of two elements from an
+  /// array of three names:
+  ///
+  ///     let names = ["Alex", "Celeste", "Davide"]
+  ///     for perm in names.permutations(ofCount: 2) {
+  ///         print(perm.joined(separator: ", "))
+  ///     }
+  ///     // Alex, Celeste
+  ///     // Alex, Davide
+  ///     // Celeste, Alex
+  ///     // Celeste, Davide
+  ///     // Davide, Alex
+  ///     // Davide, Celeste
+  ///
+  /// The permutations present the elements in increasing lexicographic order
+  /// of the collection's original ordering (rather than the order of the
+  /// elements themselves). The first permutation will always consist of
+  /// elements in their original order, and the last will have the elements in
+  /// the reverse of their original order.
+  ///
+  /// Values that are repeated in the original collection are always treated as
+  /// separate values in the resulting permutations:
+  ///
+  ///     let numbers = [20, 10, 10]
+  ///     for perm in numbers.permutations() {
+  ///         print(perm)
+  ///     }
+  ///     // [20, 10, 10]
+  ///     // [20, 10, 10]
+  ///     // [10, 20, 10]
+  ///     // [10, 10, 20]
+  ///     // [10, 20, 10]
+  ///     // [10, 10, 20]
+  ///
+  /// If `k` is zero, the resulting sequence has exactly one element, an
+  /// empty array. If `k` is greater than the number of elements in this
+  /// sequence, the resulting sequence has no elements.
+  ///
+  /// - Parameter k: The number of elements to include in each permutation.
+  ///   If `k` is `nil`, the resulting sequence represents permutations of this
+  ///   entire collection. If `k` is greater than the number of elements in
+  ///   this collection, the resulting sequence is empty.
+  ///
+  /// - Complexity: O(1) for random-access base collections. O(*n*) where *n*
+  ///   is the number of elements in the base collection, since
+  ///   `PermutationsSequence` accesses the `count` of the base collection.
+  @inlinable
+  public func permutations(ofCount k: Int? = nil) -> PermutationsSequence<Self> {
+    precondition(
+      k ?? 0 >= 0,
+      "Can't have permutations with a negative number of elements.")
+    return PermutationsSequence(self, k: k)
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// uniquePermutations()
+//===----------------------------------------------------------------------===//
+
+/// A sequence of the unique permutations of the elements of a sequence or
+/// collection.
+///
+/// To create a `UniquePermutationsSequence` instance, call one of the
+/// `uniquePermutations` methods on your collection.
+public struct UniquePermutationsSequence<Base: Collection> {
+  /// The base collection to iterate over for permutations.
+  @usableFromInline
+  internal let base: Base
+  
+  @usableFromInline
+  internal var indexes: [Base.Index]
+  
+  @usableFromInline
+  internal let kRange: Range<Int>
+}
+
+extension UniquePermutationsSequence where Base.Element: Hashable {
+  @inlinable
+  internal static func _indexes(_ base: Base) -> [Base.Index] {
+    let firstIndexesAndCountsByElement = Dictionary(
+      base.indices.lazy.map { (base[$0], ($0, 1)) },
+      uniquingKeysWith: { indexAndCount, _ in (indexAndCount.0, indexAndCount.1 + 1) })
+    
+    return firstIndexesAndCountsByElement
+      .values.sorted(by: { $0.0 < $1.0 })
+      .flatMap { index, count in repeatElement(index, count: count) }
+  }
+  
+  @inlinable
+  internal init(_ elements: Base) {
+    self.indexes = Self._indexes(elements)
+    self.base = elements
+    self.kRange = self.indexes.count ..< (self.indexes.count + 1)
+  }
+
+  @inlinable
+  internal init<R: RangeExpression>(_ base: Base, _ range: R)
+    where R.Bound == Int
+  {
+    self.indexes = Self._indexes(base)
+    self.base = base
+    
+    let upperBound = self.indexes.count + 1
+    self.kRange = range.relative(to: 0 ..< .max)
+      .clamped(to: 0 ..< upperBound)
+  }
+}
+
+extension UniquePermutationsSequence: Sequence {
+  /// The iterator for a `UniquePermutationsSequence` instance.
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal let base: Base
+    
+    @usableFromInline
+    internal var indexes: [Base.Index]
+    
+    @usableFromInline
+    internal var lengths: Range<Int>
+
+    @usableFromInline
+    internal var initial = true
+
+    @inlinable
+    internal init(_ elements: Base, indexes: [Base.Index], lengths: Range<Int>) {
+      self.base = elements
+      self.indexes = indexes
+      self.lengths = lengths
+    }
+    
+    @inlinable
+    public mutating func next() -> [Base.Element]? {
+      // In the end case, `lengths` is an empty range.
+      if lengths.isEmpty {
+        return nil
+      }
+      
+      // The first iteration must produce the original sorted array, before any
+      // permutations. We skip the permutation the first time so that we can
+      // always mutate the array _before_ returning a slice, which avoids
+      // copying when possible.
+      if initial {
+        initial = false
+        return indexes[..<lengths.lowerBound].map { base[$0] }
+      }
+
+      if !indexes.nextPermutation(upperBound: lengths.lowerBound) {
+        lengths.removeFirst()
+
+        if lengths.isEmpty {
+          return nil
+        }
+      }
+      
+      return indexes[..<lengths.lowerBound].map { base[$0] }
+    }
+  }
+  
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(base, indexes: indexes, lengths: kRange)
+  }
+}
+
+extension UniquePermutationsSequence: LazySequenceProtocol
+  where Base: LazySequenceProtocol {}
+
+extension Collection where Element: Hashable {
+  /// Returns a sequence of the unique permutations of this sequence of the
+  /// specified length.
+  ///
+  /// Use this method to iterate over the unique permutations of a sequence
+  /// with repeating elements. This example prints every unique two-element
+  /// permutation of an array of numbers:
+  ///
+  ///     let numbers = [1, 1, 2]
+  ///     for perm in numbers.uniquePermutations(ofCount: 2) {
+  ///         print(perm)
+  ///     }
+  ///     // [1, 1]
+  ///     // [1, 2]
+  ///     // [2, 1]
+  ///
+  /// By contrast, the `permutations(ofCount:)` method permutes a collection's
+  /// elements by position, and can include permutations with equal elements
+  /// in each permutation:
+  ///
+  ///     for perm in numbers.permutations(ofCount: 2)
+  ///         print(perm)
+  ///     }
+  ///     // [1, 1]
+  ///     // [1, 1]
+  ///     // [1, 2]
+  ///     // [1, 2]
+  ///     // [2, 1]
+  ///     // [2, 1]
+  ///
+  /// The returned permutations are in lexicographically sorted order.
+  ///
+  /// - Parameter k: The number of elements to include in each permutation.
+  ///   If `k` is `nil`, the resulting sequence represents permutations of this
+  ///   entire collection. If `k` is greater than the number of elements in
+  ///   this collection, the resulting sequence is empty.
+  ///
+  /// - Complexity: O(*n*), where *n* is the number of elements in this
+  ///   collection.
+  @inlinable
+  public func uniquePermutations(ofCount k: Int? = nil)
+    -> UniquePermutationsSequence<Self>
+  {
+    if let k = k {
+      return UniquePermutationsSequence(self, k ..< (k + 1))
+    } else {
+      return UniquePermutationsSequence(self)
+    }
+  }
+
+  /// Returns a collection of the unique permutations of this sequence with
+  /// lengths in the specified range.
+  ///
+  /// Use this method to iterate over the unique permutations of a sequence
+  /// with repeating elements. This example prints every unique permutation
+  /// of an array of numbers with lengths through 2 elements:
+  ///
+  ///     let numbers = [1, 1, 2]
+  ///     for perm in numbers.uniquePermutations(ofCount: ...2) {
+  ///         print(perm)
+  ///     }
+  ///     // []
+  ///     // [1]
+  ///     // [2]
+  ///     // [1, 1]
+  ///     // [1, 2]
+  ///     // [2, 1]
+  ///
+  /// The returned permutations are in ascending order by length, and then
+  /// lexicographically within each group of the same length.
+  ///
+  /// - Parameter kRange: A range of the number of elements to include in each
+  ///   permutation. `kRange` can be any integer range expression, and is
+  ///   clamped to the number of elements in this collection. Passing a range
+  ///   covering sizes greater than the number of elements in this collection
+  ///   results in an empty sequence.
+  ///
+  /// - Complexity: O(*n*), where *n* is the number of elements in this
+  ///   collection.
+  @inlinable
+  public func uniquePermutations<R: RangeExpression>(
+    ofCount kRange: R
+  ) -> UniquePermutationsSequence<Self> where R.Bound == Int {
+    UniquePermutationsSequence(self, kRange)
+  }
+}

+ 488 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Product.swift

@@ -0,0 +1,488 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+/// A sequence that represents the product of two sequences' elements.
+public struct Product2Sequence<Base1: Sequence, Base2: Collection> {
+  /// The outer sequence in the product.
+  @usableFromInline
+  internal let base1: Base1
+  
+  /// The inner sequence in the product.
+  @usableFromInline
+  internal let base2: Base2
+  
+  @inlinable
+  internal init(_ base1: Base1, _ base2: Base2) {
+    self.base1 = base1
+    self.base2 = base2
+  }
+}
+
+extension Product2Sequence: Sequence {
+  public typealias Element = (Base1.Element, Base2.Element)
+  
+  /// The iterator for a `Product2Sequence` sequence.
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal var i1: Base1.Iterator
+    @usableFromInline
+    internal var i2: Base2.Iterator
+    @usableFromInline
+    internal var element1: Base1.Element?
+    @usableFromInline
+    internal let base2: Base2
+
+    @inlinable
+    internal init(_ c: Product2Sequence) {
+      self.base2 = c.base2
+      self.i1 = c.base1.makeIterator()
+      self.i2 = c.base2.makeIterator()
+      self.element1 = nil
+    }
+    
+    @inlinable
+    public mutating func next() -> (Base1.Element,
+                                    Base2.Element)? {
+      // This is the initial state, where i1.next() has never
+      // been called, or the final state, where i1.next() has
+      // already returned nil.
+      if element1 == nil {
+        element1 = i1.next()
+        // once Base1 is exhausted, return `nil` forever
+        if element1 == nil { return nil }
+      }
+      
+      // Get the next element from the second sequence, if not
+      // at end.
+      if let element2 = i2.next() {
+        return (element1!, element2)
+      }
+      
+      // We've reached the end of the second sequence, so:
+      // 1) Get the next element of the first sequence, if exists
+      // 2) Restart iteration of the second sequence
+      // 3) Get the first element of the second sequence, if exists
+      element1 = i1.next()
+      guard let element1 = element1
+        else { return nil }
+      
+      i2 = base2.makeIterator()
+      if let element2 = i2.next() {
+        return (element1, element2)
+      } else {
+        return nil
+      }
+    }
+  }
+
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(self)
+  }
+}
+
+extension Product2Sequence: Collection where Base1: Collection {
+  /// The index type for a `Product2Sequence` collection.
+  public struct Index: Comparable {
+    @usableFromInline
+    internal var i1: Base1.Index
+    @usableFromInline
+    internal var i2: Base2.Index
+    
+    @inlinable
+    internal init(i1: Base1.Index, i2: Base2.Index) {
+      self.i1 = i1
+      self.i2 = i2
+    }
+    
+    @inlinable
+    public static func < (lhs: Index, rhs: Index) -> Bool {
+      (lhs.i1, lhs.i2) < (rhs.i1, rhs.i2)
+    }
+  }
+  
+  @inlinable
+  public var count: Int {
+    base1.count * base2.count
+  }
+  
+  @inlinable
+  public var startIndex: Index {
+    Index(
+      i1: base2.isEmpty ? base1.endIndex : base1.startIndex,
+      i2: base2.startIndex)
+  }
+  
+  @inlinable
+  public var endIndex: Index {
+    // `base2.startIndex` simplifies index calculations.
+    Index(i1: base1.endIndex, i2: base2.startIndex)
+  }
+  
+  @inlinable
+  public subscript(position: Index) -> (Base1.Element,
+                                        Base2.Element) {
+    (base1[position.i1], base2[position.i2])
+  }
+  
+  /// Forms an index from a pair of base indices, normalizing
+  /// `(i, base2.endIndex)` to `(base1.index(after: i), base2.startIndex)` if
+  /// necessary.
+  @inlinable
+  internal func normalizeIndex(_ i1: Base1.Index, _ i2: Base2.Index) -> Index {
+    i2 == base2.endIndex
+      ? Index(i1: base1.index(after: i1), i2: base2.startIndex)
+      : Index(i1: i1, i2: i2)
+  }
+  
+  @inlinable
+  public func index(after i: Index) -> Index {
+    precondition(i.i1 != base1.endIndex, "Can't advance past endIndex")
+    return normalizeIndex(i.i1, base2.index(after: i.i2))
+  }
+  
+  @inlinable
+  public func distance(from start: Index, to end: Index) -> Int {
+    guard start.i1 <= end.i1
+      else { return -distance(from: end, to: start) }
+    guard start.i1 != end.i1
+      else { return base2.distance(from: start.i2, to: end.i2) }
+    
+    // The number of full cycles through `base2` between `start` and `end`,
+    // excluding the cycles that `start` and `end` are on.
+    let fullBase2Cycles = base1[start.i1..<end.i1].count - 1
+    
+    if start.i2 <= end.i2 {
+      //               start.i2
+      //                  v
+      // start.i1 > [l l l|c c c c c c r r r]
+      //            [l l l c c c c c c r r r] >
+      //                       ...            > `fullBase2Cycles` times
+      //            [l l l c c c c c c r r r] >
+      //   end.i1 > [l l l c c c c c c|r r r]
+      //                              ^
+      //                            end.i2
+      
+      let left = base2[..<start.i2].count
+      let center = base2[start.i2..<end.i2].count
+      let right = base2[end.i2...].count
+      
+      return center + right
+        + fullBase2Cycles * (left + center + right)
+        + left + center
+    } else {
+      //                           start.i2
+      //                              v
+      // start.i1 > [l l l c c c c c c|r r r]
+      //            [l l l c c c c c c r r r] >
+      //                       ...            > `fullBase2Cycles` times
+      //            [l l l c c c c c c r r r] >
+      //   end.i1 > [l l l|c c c c c c r r r]
+      //                  ^
+      //                end.i2
+      
+      let left = base2[..<end.i2].count
+      let right = base2[start.i2...].count
+      
+      // We can avoid traversing `base2[end.i2..<start.i2]` if `start` and `end`
+      // are on consecutive cycles.
+      guard fullBase2Cycles > 0 else { return right + left }
+      
+      let center = base2[end.i2..<start.i2].count
+      return right
+        + fullBase2Cycles * (left + center + right)
+        + left
+    }
+  }
+  
+  @inlinable
+  public func index(_ i: Index, offsetBy distance: Int) -> Index {
+    guard distance != 0 else { return i }
+    
+    return distance > 0
+      ? offsetForward(i, by: distance)
+      : offsetBackward(i, by: -distance)
+  }
+  
+  @inlinable
+  public func index(
+    _ i: Index,
+    offsetBy distance: Int,
+    limitedBy limit: Index
+  ) -> Index? {
+    if distance >= 0 {
+      return limit >= i
+        ? offsetForward(i, by: distance, limitedBy: limit)
+        : offsetForward(i, by: distance)
+    } else {
+      return limit <= i
+        ? offsetBackward(i, by: -distance, limitedBy: limit)
+        : offsetBackward(i, by: -distance)
+    }
+  }
+
+  @inlinable
+  internal func offsetForward(_ i: Index, by distance: Int) -> Index {
+    guard let index = offsetForward(i, by: distance, limitedBy: endIndex)
+      else { fatalError("Index is out of bounds") }
+    return index
+  }
+  
+  @inlinable
+  internal func offsetBackward(_ i: Index, by distance: Int) -> Index {
+    guard let index = offsetBackward(i, by: distance, limitedBy: startIndex)
+      else { fatalError("Index is out of bounds") }
+    return index
+  }
+  
+  @inlinable
+  internal func offsetForward(
+    _ i: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance >= 0)
+    assert(limit >= i)
+    
+    if limit.i1 == i.i1 {
+      // Delegate to `base2` if the offset is limited to `i.i1`.
+      //
+      //             i.i2      limit.i2
+      //              v           v
+      // i.i1 > [x x x|x x x x x x|x x x]
+      
+      return base2.index(i.i2, offsetBy: distance, limitedBy: limit.i2)
+        .map { i2 in Index(i1: i.i1, i2: i2) }
+    }
+    
+    
+    if let i2 = base2.index(i.i2, offsetBy: distance, limitedBy: base2.endIndex) {
+      // `distance` does not overflow `base2[i.i2...]`.
+      //
+      //             i.i2         i2
+      //              v           v
+      // i.i1 > [x x x|x x x x x x|x x x]
+      //        [     |> > > > > >|     ]   (`distance`)
+      
+      return normalizeIndex(i.i1, i2)
+    }
+    
+    let suffixCount = base2[i.i2...].count
+    let remaining = distance - suffixCount
+    let nextI1 = base1.index(after: i.i1)
+    
+    if limit.i1 == nextI1 {
+      // Delegate to `base2` if the offset is limited to `nextI1`.
+      //
+      //               i.i2
+      //                v
+      //   i.i1 > [x x x|x x x x x x x x x]
+      // nextI1 > [x x x x x x x x x|x x x]
+      //                            ^
+      //                         limit.i2
+      
+      return base2.index(base2.startIndex, offsetBy: remaining, limitedBy: limit.i2)
+        .map { i2 in Index(i1: nextI1, i2: i2) }
+    }
+    
+    if let i2 = base2.index(base2.startIndex, offsetBy: remaining, limitedBy: i.i2) {
+      // `remaining` does not overflow `base2[..<i.i2]`.
+      //
+      //                           i.i2
+      //                            v
+      //   i.i1 > [x x x x x x x x x|x x x]
+      //          [                 |> > >]   (`suffixCount`)
+      //          [> > >|                 ]   (`remaining`)
+      // nextI1 > [x x x|x x x x x x x x x]
+      //                ^
+      //                i2
+      
+      return Index(i1: nextI1, i2: i2)
+    }
+    
+    let prefixCount = base2[..<i.i2].count
+    let base2Count = prefixCount + suffixCount
+    let base1Distance = remaining / base2Count
+    
+    guard let i1 = base1.index(nextI1, offsetBy: base1Distance, limitedBy: limit.i1)
+      else { return nil }
+    
+    // The distance from `base2.startIndex` to the target.
+    let base2Distance = remaining % base2Count
+    
+    let base2Limit = limit.i1 == i1 ? limit.i2 : base2.endIndex
+    return base2.index(base2.startIndex, offsetBy: base2Distance, limitedBy: base2Limit)
+      .map { i2 in Index(i1: i1, i2: i2) }
+  }
+
+  @inlinable
+  internal func offsetBackward(
+    _ i: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance >= 0)
+    assert(limit <= i)
+    
+    if limit.i1 == i.i1 {
+      // Delegate to `base2` if the offset is limited to `i.i1`.
+      //
+      //           limit.i2      i.i2
+      //              v           v
+      // i.i1 > [x x x|x x x x x x|x x x]
+      
+      return base2.index(i.i2, offsetBy: -distance, limitedBy: limit.i2)
+        .map { i2 in Index(i1: i.i1, i2: i2) }
+    }
+    
+    if let i2 = base2.index(i.i2, offsetBy: -distance, limitedBy: base2.startIndex) {
+      // `distance` does not underflow `base2[..<i.i2]`.
+      //
+      //              i2         i.i2
+      //              v           v
+      // i.i1 > [x x x|x x x x x x|x x x]
+      //        [     |< < < < < <|     ]   (`distance`)
+      
+      return Index(i1: i.i1, i2: i2)
+    }
+    
+    let prefixCount = base2[..<i.i2].count
+    let remaining = distance - prefixCount
+    let previousI1 = base1.index(i.i1, offsetBy: -1)
+    
+    if limit.i1 == previousI1 {
+      // Delegate to `base2` if the offset is limited to `previousI1`.
+      //
+      //                 limit.i2
+      //                    v
+      // previousI1 > [x x x|x x x x x x x x x]
+      //       i.i1 > [x x x x x x x x x|x x x]
+      //                                ^
+      //                               i.i2
+      
+      return base2.index(base2.endIndex, offsetBy: -remaining, limitedBy: limit.i2)
+        .map { i2 in Index(i1: previousI1, i2: i2) }
+    }
+    
+    if let i2 = base2.index(base2.endIndex, offsetBy: -remaining, limitedBy: i.i2) {
+      // `remaining` does not underflow `base2[i.i2...]`.
+      //
+      //                                i2
+      //                                v
+      // previousI1 > [x x x x x x x x x|x x x]
+      //              [                 |< < <]   (`remaining`)
+      //              [< < <|                 ]   (`prefixCount`)
+      //       i.i1 > [x x x|x x x x x x x x x]
+      //                    ^
+      //                   i.i2
+      
+      return Index(i1: previousI1, i2: i2)
+    }
+    
+    let suffixCount = base2[i.i2...].count
+    let base2Count = prefixCount + suffixCount
+    let base1Distance = remaining / base2Count
+    
+    // The distance from `base2.endIndex` to the target.
+    let base2Distance = remaining % base2Count
+    
+    if base2Distance == 0 {
+      // We end up exactly between two cycles, so `base1Distance` would
+      // overshoot the target by 1.
+      //
+      //       base2.startIndex
+      //              v
+      //         i1 > |x x x x x x x x x x x x] >
+      //                         ...            > `base1Distance` times
+      // previousI1 > [x x x x x x x x x x x x] >
+      //       i.i1 > [x x x|x x x x x x x x x]
+      //                    ^
+      //                   i.i2
+      
+      if let i1 = base1.index(previousI1, offsetBy: -(base1Distance - 1), limitedBy: limit.i1) {
+        let index = Index(i1: i1, i2: base2.startIndex)
+        return index < limit ? nil : index
+      } else {
+        return nil
+      }
+    }
+    
+    guard let i1 = base1.index(previousI1, offsetBy: -base1Distance, limitedBy: limit.i1)
+      else { return nil }
+    
+    let base2Limit = limit.i1 == i1 ? limit.i2 : base2.startIndex
+    return base2.index(base2.endIndex, offsetBy: -base2Distance, limitedBy: base2Limit)
+      .map { i2 in Index(i1: i1, i2: i2) }
+  }
+}
+
+extension Product2Sequence: BidirectionalCollection
+  where Base1: BidirectionalCollection, Base2: BidirectionalCollection
+{
+  @inlinable
+  public func index(before i: Index) -> Index {
+    precondition(i != startIndex,
+                 "Can't move before startIndex")
+    if i.i2 == base2.startIndex {
+      return Index(
+        i1: base1.index(before: i.i1),
+        i2: base2.index(before: base2.endIndex))
+    } else {
+      return Index(i1: i.i1, i2: base2.index(before: i.i2))
+    }
+  }
+}
+
+extension Product2Sequence: RandomAccessCollection
+  where Base1: RandomAccessCollection, Base2: RandomAccessCollection {}
+
+extension Product2Sequence.Index: Hashable
+  where Base1.Index: Hashable, Base2.Index: Hashable {}
+
+//===----------------------------------------------------------------------===//
+// product(_:_:)
+//===----------------------------------------------------------------------===//
+
+/// Creates a sequence of each pair of elements of two underlying sequences.
+///
+/// Use this function to iterate over every pair of elements in two different
+/// collections. The returned sequence yields 2-element tuples, where the first
+/// element of the tuple is from the first collection and the second element is
+/// from the second collection.
+///
+///
+///     let numbers = 1...3
+///     let colors = ["cerise", "puce", "heliotrope"]
+///     for (number, color) in product(numbers, colors) {
+///         print("\(number): \(color)")
+///     }
+///     // 1: cerise
+///     // 1: puce
+///     // 1: heliotrope
+///     // 2: cerise
+///     // 2: puce
+///     // 2: heliotrope
+///     // 3: cerise
+///     // 3: puce
+///     // 3: heliotrope
+///
+/// The order of tuples in the returned sequence is consistent. The first
+/// element of the first collection is paired with each element of the second
+/// collection, then the second element of the first collection is paired with
+/// each element of the second collection, and so on.
+///
+/// - Parameters:
+///   - s1: The first sequence to iterate over.
+///   - s2: The second sequence to iterate over.
+///
+/// - Complexity: O(1)
+@inlinable
+public func product<Base1: Sequence, Base2: Collection>(
+  _ s1: Base1, _ s2: Base2
+) -> Product2Sequence<Base1, Base2> {
+  Product2Sequence(s1, s2)
+}

+ 620 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Reductions.swift

@@ -0,0 +1,620 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+// MARK: - Exclusive Reductions
+
+extension LazySequenceProtocol {
+  /// Returns a sequence containing the accumulated results of combining the
+  /// elements of the sequence using the given closure.
+  ///
+  /// This can be seen as applying the reduce function to each element and
+  /// providing the initial value followed by these results as a sequence.
+  ///
+  /// ```
+  /// let runningTotal = [1, 2, 3, 4].lazy.reductions(0, +)
+  /// print(Array(runningTotal))
+  ///
+  /// // prints [0, 1, 3, 6, 10]
+  /// ```
+  ///
+  /// - Parameters:
+  ///   - initial: The value to use as the initial value.
+  ///   - transform: A closure that combines the previously reduced result and
+  ///     the next element in the receiving sequence.
+  /// - Returns: A sequence of the initial value followed by the reduced
+  ///   elements.
+  ///
+  /// - Complexity: O(1)
+  @inlinable
+  public func reductions<Result>(
+    _ initial: Result,
+    _ transform: @escaping (Result, Element) -> Result
+  ) -> ExclusiveReductionsSequence<Elements, Result> {
+    reductions(into: initial) { result, element in
+      result = transform(result, element)
+    }
+  }
+
+  /// Returns a sequence containing the accumulated results of combining the
+  /// elements of the sequence using the given closure.
+  ///
+  /// This can be seen as applying the reduce function to each element and
+  /// providing the initial value followed by these results as a sequence.
+  ///
+  /// ```
+  /// let runningTotal = [1, 2, 3, 4].lazy.reductions(into: 0, +)
+  /// print(Array(runningTotal))
+  ///
+  /// // prints [0, 1, 3, 6, 10]
+  /// ```
+  ///
+  /// - Parameters:
+  ///   - initial: The value to use as the initial value.
+  ///   - transform: A closure that combines the previously reduced result and
+  ///     the next element in the receiving sequence.
+  /// - Returns: A sequence of the initial value followed by the reduced
+  /// elements.
+  ///
+  /// - Complexity: O(1)
+  @inlinable
+  public func reductions<Result>(
+    into initial: Result,
+    _ transform: @escaping (inout Result, Element) -> Void
+  ) -> ExclusiveReductionsSequence<Elements, Result> {
+    ExclusiveReductionsSequence(
+      base: elements,
+      initial: initial,
+      transform: transform)
+  }
+}
+
+extension Sequence {
+  /// Returns an array containing the accumulated results of combining the
+  /// elements of the sequence using the given closure.
+  ///
+  /// This can be seen as applying the reduce function to each element and
+  /// providing the initial value followed by these results as a sequence.
+  ///
+  /// ```
+  /// let runningTotal = [1, 2, 3, 4].reductions(0, +)
+  /// print(runningTotal)
+  ///
+  /// // prints [0, 1, 3, 6, 10]
+  /// ```
+  ///
+  /// When `reductions(_:_:)` is called, the following steps occur:
+  ///
+  ///   1. The `initial` result is added to an array of results.
+  ///   2. The `transform` closure is called with the `initial` result and the
+  ///   first element of the sequence, appending the result to the array.
+  ///   3. The closure is called again repeatedly with the updated accumulating
+  ///   result and each element of the sequence, adding each result to the
+  ///   array.
+  ///   4. When the sequence is exhausted, the results array is returned to the
+  ///   caller.
+  ///
+  ///   If the sequence has no elements, `transform` is never executed and
+  ///   an array containing only the `initial` result is returned.
+  ///
+  /// - Parameters:
+  ///   - initial: The value to use as the initial value.
+  ///   - transform: A closure that combines the previously reduced result and
+  ///     the next element in the receiving sequence.
+  /// - Returns: An array of the initial value followed by the reduced elements.
+  ///
+  /// - Complexity: O(_n_), where _n_ is the length of the sequence.
+  @inlinable
+  public func reductions<Result>(
+    _ initial: Result,
+    _ transform: (Result, Element) throws -> Result
+  ) rethrows -> [Result] {
+    try reductions(into: initial) { result, element in
+      result = try transform(result, element)
+    }
+  }
+
+  /// Returns an array containing the accumulated results of combining the
+  /// elements of the sequence using the given closure.
+  ///
+  /// This can be seen as applying the reduce function to each element and
+  /// providing the initial value followed by these results as a sequence.
+  ///
+  /// ```
+  /// let runningTotal = [1, 2, 3, 4].reductions(into: 0, +)
+  /// print(runningTotal)
+  ///
+  /// // prints [0, 1, 3, 6, 10]
+  /// ```
+  ///
+  /// When `reductions(into:_:_)` is called, the following steps occur:
+  ///
+  ///   1. The `initial` result is added to an array of results.
+  ///   2. The `transform` closure is called with the `initial` result and the
+  ///   first element of the sequence, appending the result to the array.
+  ///   3. The closure is called again repeatedly with the updated accumulating
+  ///   result and each element of the sequence, adding each result to the
+  ///   array.
+  ///   4. When the sequence is exhausted, the results array is returned to the
+  ///   caller.
+  ///
+  ///   If the sequence has no elements, `transform` is never executed and
+  ///   an array containing only the `initial` result is returned.
+  ///
+  /// - Parameters:
+  ///   - initial: The value to use as the initial value.
+  ///   - transform: A closure that combines the previously reduced result and
+  ///     the next element in the receiving sequence.
+  /// - Returns: An array of the initial value followed by the reduced elements.
+  ///
+  /// - Complexity: O(_n_), where _n_ is the length of the sequence.
+  @inlinable
+  public func reductions<Result>(
+    into initial: Result,
+    _ transform: (inout Result, Element) throws -> Void
+  ) rethrows -> [Result] {
+
+    var output = [Result]()
+    output.reserveCapacity(underestimatedCount + 1)
+    output.append(initial)
+
+    var initial = initial
+    for element in self {
+      try transform(&initial, element)
+      output.append(initial)
+    }
+
+    return output
+  }
+}
+
+/// A sequence of applying a transform to the element of a sequence and the
+/// previously transformed result.
+public struct ExclusiveReductionsSequence<Base: Sequence, Result> {
+  @usableFromInline
+  internal let base: Base
+
+  @usableFromInline
+  internal let initial: Result
+
+  @usableFromInline
+  internal let transform: (inout Result, Base.Element) -> Void
+
+  @inlinable
+  internal init(
+    base: Base,
+    initial: Result,
+    transform: @escaping (inout Result, Base.Element) -> Void
+  ) {
+    self.base = base
+    self.initial = initial
+    self.transform = transform
+  }
+}
+
+extension ExclusiveReductionsSequence: Sequence {
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal var iterator: Base.Iterator
+
+    @usableFromInline
+    internal var current: Result?
+
+    @usableFromInline
+    internal let transform: (inout Result, Base.Element) -> Void
+
+    @inlinable
+    internal init(
+      iterator: Base.Iterator,
+      current: Result? = nil,
+      transform: @escaping (inout Result, Base.Element) -> Void
+    ) {
+      self.iterator = iterator
+      self.current = current
+      self.transform = transform
+    }
+
+    @inlinable
+    public mutating func next() -> Result? {
+      guard let result = current else { return nil }
+      current = iterator.next().map { element in
+        var result = result
+        transform(&result, element)
+        return result
+      }
+      return result
+    }
+  }
+
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(
+      iterator: base.makeIterator(),
+      current: initial,
+      transform: transform)
+  }
+}
+
+extension ExclusiveReductionsSequence: Collection where Base: Collection {
+  public struct Index: Comparable {
+    @usableFromInline
+    internal enum Representation {
+      case base(Base.Index, Result)
+      case end
+    }
+    
+    @usableFromInline
+    internal let representation: Representation
+
+    @inlinable
+    internal init(_ representation: Representation) {
+      self.representation = representation
+    }
+    
+    @inlinable
+    public static func == (lhs: Self, rhs: Self) -> Bool {
+      switch (lhs.representation, rhs.representation) {
+      case (.base(let lhs, _), .base(let rhs, _)):
+        return lhs == rhs
+      case (.end, .end):
+        return true
+      case (.base, .end), (.end, .base):
+        return false
+      }
+    }
+    
+    @inlinable
+    public static func < (lhs: Self, rhs: Self) -> Bool {
+      switch (lhs.representation, rhs.representation) {
+      case (.end, _):
+        return false
+      case (_, .end):
+        return true
+      case (.base(let lhs, _), .base(let rhs, _)):
+        return lhs < rhs
+      }
+    }
+  }
+
+  @inlinable
+  public var startIndex: Index {
+    Index(.base(base.startIndex, initial))
+  }
+
+  @inlinable
+  public var endIndex: Index {
+    Index(.end)
+  }
+
+  @inlinable
+  public subscript(position: Index) -> Result {
+    switch position.representation {
+    case .base(_, let result):
+      return result
+    case .end:
+      fatalError("Cannot get element of end index.")
+    }
+  }
+
+  @inlinable
+  public func index(after index: Index) -> Index {
+    switch index.representation {
+    case .base(base.endIndex, _):
+      return Index(.end)
+    case .base(let index, var result):
+      transform(&result, base[index])
+      return Index(.base(base.index(after: index), result))
+    case .end:
+      fatalError("Cannot get index after end index.")
+    }
+  }
+
+  @inlinable
+  public func distance(from start: Index, to end: Index) -> Int {
+    switch (start.representation, end.representation) {
+    case let (.base(start, _), .base(end, _)):
+      return base.distance(from: start, to: end)
+    case let (.base(index, _), .end):
+      return base.distance(from: index, to: base.endIndex) + 1
+    case let (.end, .base(index, _)):
+      return base.distance(from: base.endIndex, to: index) - 1
+    case (.end, .end):
+      return 0
+    }
+  }
+}
+
+extension ExclusiveReductionsSequence: LazySequenceProtocol {}
+
+extension ExclusiveReductionsSequence: LazyCollectionProtocol
+  where Base: Collection {}
+
+extension ExclusiveReductionsSequence.Index: Hashable
+  where Base.Index: Hashable
+{
+  @inlinable
+  public func hash(into hasher: inout Hasher) {
+    switch representation {
+    case .base(let base, _):
+      hasher.combine(base)
+    case .end:
+      break
+    }
+  }
+}
+
+// MARK: - Inclusive Reductions
+
+extension LazySequenceProtocol {
+  /// Returns a sequence containing the accumulated results of combining the
+  /// elements of the sequence using the given closure.
+  ///
+  /// This can be seen as applying the reduce function to each element and
+  /// providing the initial value followed by these results as a sequence.
+  ///
+  /// ```
+  /// let runningTotal = [1, 2, 3, 4].lazy.reductions(+)
+  /// print(Array(runningTotal))
+  ///
+  /// // prints [1, 3, 6, 10]
+  /// ```
+  ///
+  /// - Parameter transform: A closure that combines the previously reduced
+  ///   result and the next element in the receiving sequence.
+  /// - Returns: A sequence of the reduced elements.
+  ///
+  /// - Complexity: O(1)
+  @inlinable
+  public func reductions(
+    _ transform: @escaping (Element, Element) -> Element
+  ) -> InclusiveReductionsSequence<Elements> {
+    InclusiveReductionsSequence(base: elements, transform: transform)
+  }
+}
+
+extension Sequence {
+  /// Returns an array containing the accumulated results of combining the
+  /// elements of the sequence using the given closure.
+  ///
+  /// This can be seen as applying the reduce function to each element and
+  /// providing the initial value followed by these results as a sequence.
+  ///
+  /// ```
+  /// let runningTotal = [1, 2, 3, 4].reductions(+)
+  /// print(runningTotal)
+  ///
+  /// // prints [1, 3, 6, 10]
+  /// ```
+  ///
+  /// When `reductions(_:)` is called, the following steps occur:
+  ///
+  ///   1. The `transform` closure is called with the first and second elements
+  ///   of the sequence, appending the result to an array of results.
+  ///   2. The closure is called again repeatedly with the updated accumulating
+  ///   result and the next element of the sequence, adding each result to the
+  ///   array.
+  ///   3. When the sequence is exhausted, the results array is returned to the
+  ///   caller.
+  ///
+  ///   If the sequence has no elements, `transform` is never executed and
+  ///   an empty array is returned.
+  ///
+  ///   If the sequence has one element, `transform` is never executed and
+  ///   an array containing only that first element is returned.
+  ///
+  /// - Parameter transform: A closure that combines the previously reduced
+  ///   result and the next element in the receiving sequence.
+  /// - Returns: An array of the reduced elements.
+  ///
+  /// - Complexity: O(_n_), where _n_ is the length of the sequence.
+  @inlinable
+  public func reductions(
+    _ transform: (Element, Element) throws -> Element
+  ) rethrows -> [Element] {
+    var iterator = makeIterator()
+    guard let initial = iterator.next() else { return [] }
+    return try IteratorSequence(iterator).reductions(initial, transform)
+  }
+}
+
+public struct InclusiveReductionsSequence<Base: Sequence> {
+  @usableFromInline
+  internal let base: Base
+
+  @usableFromInline
+  internal let transform: (Base.Element, Base.Element) -> Base.Element
+
+  @inlinable
+  internal init(
+    base: Base,
+    transform: @escaping (Base.Element, Base.Element) -> Base.Element
+  ) {
+    self.base = base
+    self.transform = transform
+  }
+}
+
+extension InclusiveReductionsSequence: Sequence {
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal var iterator: Base.Iterator
+
+    @usableFromInline
+    internal var element: Base.Element?
+
+    @usableFromInline
+    internal let transform: (Base.Element, Base.Element) -> Base.Element
+
+    @inlinable
+    internal init(
+      iterator: Base.Iterator,
+      transform: @escaping (Base.Element, Base.Element) -> Base.Element
+    ) {
+      self.iterator = iterator
+      self.transform = transform
+    }
+
+    @inlinable
+    public mutating func next() -> Base.Element? {
+      guard let previous = element else {
+        element = iterator.next()
+        return element
+      }
+      guard let next = iterator.next() else { return nil }
+      element = transform(previous, next)
+      return element
+    }
+  }
+
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(iterator: base.makeIterator(), transform: transform)
+  }
+}
+
+extension InclusiveReductionsSequence: Collection where Base: Collection {
+  public struct Index: Comparable {
+    @usableFromInline
+    internal let base: Base.Index
+    
+    @usableFromInline
+    internal let result: Element?
+
+    @inlinable
+    internal init(base: Base.Index, result: Element?) {
+      self.base = base
+      self.result = result
+    }
+
+    @inlinable
+    public static func < (lhs: Self, rhs: Self) -> Bool {
+      lhs.base < rhs.base
+    }
+    
+    @inlinable
+    public static func == (lhs: Self, rhs: Self) -> Bool {
+      lhs.base == rhs.base
+    }
+  }
+
+  @inlinable
+  public var startIndex: Index {
+    Index(base: base.startIndex, result: base.first)
+  }
+
+  @inlinable
+  public var endIndex: Index {
+    Index(base: base.endIndex, result: nil)
+  }
+
+  @inlinable
+  public subscript(index: Index) -> Base.Element {
+    guard let result = index.result else {
+      fatalError("Can't subscript using endIndex")
+    }
+    
+    return result
+  }
+
+  @inlinable
+  public func index(after index: Index) -> Index {
+    guard let result = index.result else {
+      fatalError("Can't advance past endIndex")
+    }
+    
+    let index = base.index(after: index.base)
+    let nextResult = index == base.endIndex
+      ? nil
+      : transform(result, base[index])
+    
+    return Index(base: index, result: nextResult)
+  }
+
+  @inlinable
+  public func distance(from start: Index, to end: Index) -> Int {
+    base.distance(from: start.base, to: end.base)
+  }
+}
+
+extension InclusiveReductionsSequence: LazySequenceProtocol {}
+
+extension InclusiveReductionsSequence: LazyCollectionProtocol
+  where Base: Collection {}
+
+extension InclusiveReductionsSequence.Index: Hashable
+  where Base.Index: Hashable
+{
+  @inlinable
+  public func hash(into hasher: inout Hasher) {
+    hasher.combine(base)
+  }
+}
+
+// MARK: - Scan
+
+extension LazySequenceProtocol {
+  @available(*, deprecated, message: "Use reductions(_:_:) instead.")
+  @inlinable
+  public func scan<Result>(
+    _ initial: Result,
+    _ transform: @escaping (Result, Element) -> Result
+  ) -> ExclusiveReductionsSequence<Elements, Result> {
+    reductions(initial, transform)
+  }
+
+  @available(*, deprecated, message: "Use reductions(into:_:) instead.")
+  @inlinable
+  public func scan<Result>(
+    into initial: Result,
+    _ transform: @escaping (inout Result, Element) -> Void
+  ) -> ExclusiveReductionsSequence<Elements, Result> {
+    reductions(into: initial, transform)
+  }
+}
+
+extension Sequence {
+  @available(*, deprecated, message: "Use reductions(_:_:) instead.")
+  @inlinable
+  public func scan<Result>(
+    _ initial: Result,
+    _ transform: (Result, Element) throws -> Result
+  ) rethrows -> [Result] {
+    try reductions(initial, transform)
+  }
+
+  @available(*, deprecated, message: "Use reductions(into:_:) instead.")
+  @inlinable
+  public func scan<Result>(
+    into initial: Result,
+    _ transform: (inout Result, Element) throws -> Void
+  ) rethrows -> [Result] {
+    try reductions(into: initial, transform)
+  }
+}
+
+extension LazySequenceProtocol {
+  @available(*, deprecated, message: "Use reductions(_:) instead.")
+  @inlinable
+  public func scan(
+    _ transform: @escaping (Element, Element) -> Element
+  ) -> InclusiveReductionsSequence<Elements> {
+    reductions(transform)
+  }
+}
+
+extension Sequence {
+  @available(*, deprecated, message: "Use reductions(_:) instead.")
+  @inlinable
+  public func scan(
+    _ transform: (Element, Element) throws -> Element
+  ) rethrows -> [Element] {
+    try reductions(transform)
+  }
+}

+ 279 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Rotate.swift

@@ -0,0 +1,279 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// reverse(subrange:)
+//===----------------------------------------------------------------------===//
+
+extension MutableCollection where Self: BidirectionalCollection {
+  /// Reverses the elements of the collection, moving from each end until
+  /// `limit` is reached from either direction. The returned indices are the
+  /// start and end of the range of unreversed elements.
+  ///
+  ///     Input:
+  ///     [a b c d e f g h i j k l m n o p]
+  ///             ^
+  ///           limit
+  ///     Output:
+  ///     [p o n m e f g h i j k l d c b a]
+  ///             ^               ^
+  ///           lower           upper
+  ///
+  /// - Postcondition: For returned indices `(lower, upper)`:
+  ///   `lower == limit || upper == limit`
+  @inlinable
+  @discardableResult
+  internal mutating func _reverse(
+    subrange: Range<Index>, until limit: Index
+  ) -> (Index, Index) {
+    var lower = subrange.lowerBound
+    var upper = subrange.upperBound
+    while lower != limit && upper != limit {
+      formIndex(before: &upper)
+      swapAt(lower, upper)
+      formIndex(after: &lower)
+    }
+    return (lower, upper)
+  }
+  
+  /// Reverses the elements within the given subrange.
+  ///
+  /// This example reverses the numbers within the subrange at the start of the
+  /// `numbers` array:
+  ///
+  ///     var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
+  ///     numbers.reverse(subrange: 0..<4)
+  ///     // numbers == [40, 30, 20, 10, 50, 60, 70, 80]
+  ///
+  /// - Parameter subrange: The subrange of this collection to reverse.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of `subrange`.
+  @inlinable
+  public mutating func reverse(subrange: Range<Index>) {
+    if subrange.isEmpty { return }
+    var lower = subrange.lowerBound
+    var upper = subrange.upperBound
+    while lower < upper {
+      formIndex(before: &upper)
+      swapAt(lower, upper)
+      formIndex(after: &lower)
+    }
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// rotate(toStartAt:) / rotate(subrange:toStartAt:)
+//===----------------------------------------------------------------------===//
+
+extension MutableCollection {
+  /// Swaps the elements of the two given subranges, up to the upper bound of
+  /// the smaller subrange. The returned indices are the ends of the two ranges
+  /// that were actually swapped.
+  ///
+  ///     Input:
+  ///     [a b c d e f g h i j k l m n o p]
+  ///      ^^^^^^^         ^^^^^^^^^^^^^
+  ///      lhs             rhs
+  ///
+  ///     Output:
+  ///     [i j k l e f g h a b c d m n o p]
+  ///             ^               ^
+  ///             p               q
+  ///
+  /// - Precondition: !lhs.isEmpty && !rhs.isEmpty
+  /// - Postcondition: For returned indices `(p, q)`:
+  ///
+  ///   - distance(from: lhs.lowerBound, to: p) == distance(from:
+  ///     rhs.lowerBound, to: q)
+  ///   - p == lhs.upperBound || q == rhs.upperBound
+  @inlinable
+  internal mutating func _swapNonemptySubrangePrefixes(
+    _ lhs: Range<Index>, _ rhs: Range<Index>
+  ) -> (Index, Index) {
+    assert(!lhs.isEmpty)
+    assert(!rhs.isEmpty)
+    
+    var p = lhs.lowerBound
+    var q = rhs.lowerBound
+    repeat {
+      swapAt(p, q)
+      formIndex(after: &p)
+      formIndex(after: &q)
+    }
+      while p != lhs.upperBound && q != rhs.upperBound
+    return (p, q)
+  }
+
+  /// Rotates the elements within the given subrange so that the element at the
+  /// specified index becomes the start of the subrange.
+  ///
+  /// Rotating a collection is equivalent to breaking the collection into two
+  /// sections at the index `newStart`, and then swapping those two sections.
+  /// In this example, the `numbers` array is rotated so that the element at
+  /// index `3` (`40`) is first:
+  ///
+  ///     var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
+  ///     let oldStart = numbers.rotate(subrange: 0..<4, toStartAt: 2)
+  ///     // numbers == [30, 40, 10, 20, 50, 60, 70, 80]
+  ///     // numbers[oldStart] == 10
+  ///
+  /// - Parameters:
+  ///   - subrange: The subrange of this collection to rotate.
+  ///   - newStart: The index of the element that should be at the start of
+  ///     `subrange` after rotating.
+  /// - Returns: The new index of the element that was at the start of
+  ///   `subrange` pre-rotation.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of `subrange`.
+  @inlinable
+  @discardableResult
+  public mutating func rotate(
+    subrange: Range<Index>,
+    toStartAt newStart: Index
+  ) -> Index {
+    var m = newStart, s = subrange.lowerBound
+    let e = subrange.upperBound
+    
+    // Handle the trivial cases
+    if s == m { return e }
+    if m == e { return s }
+    
+    // We have two regions of possibly-unequal length that need to be exchanged.
+    // The return value of this method is going to be the position following
+    // that of the element that is currently last (element j).
+    //
+    //   [a b c d e f g|h i j]   or   [a b c|d e f g h i j]
+    //   ^             ^     ^        ^     ^             ^
+    //   s             m     e        s     m             e
+    //
+    var ret = e // start with a known incorrect result.
+    while true {
+      // Exchange the leading elements of each region (up to the length of the
+      // shorter region).
+      //
+      //   [a b c d e f g|h i j]   or   [a b c|d e f g h i j]
+      //    ^^^^^         ^^^^^          ^^^^^ ^^^^^
+      //   [h i j d e f g|a b c]   or   [d e f|a b c g h i j]
+      //   ^     ^       ^     ^         ^    ^     ^       ^
+      //   s    s1       m    m1/e       s   s1/m   m1      e
+      //
+      let (s1, m1) = _swapNonemptySubrangePrefixes(s..<m, m..<e)
+      
+      if m1 == e {
+        // Left-hand case: we have moved element j into position. If we haven't
+        // already, we can capture the return value which is in s1.
+        //
+        // Note: the STL breaks the loop into two just to avoid this comparison
+        // once the return value is known. I'm not sure it's a worthwhile
+        // optimization, though.
+        if ret == e { ret = s1 }
+        
+        // If both regions were the same size, we're done.
+        if s1 == m { break }
+      }
+      
+      // Now we have a smaller problem that is also a rotation, so we can adjust
+      // our bounds and repeat.
+      //
+      //    h i j[d e f g|a b c]   or    d e f[a b c|g h i j]
+      //         ^       ^     ^              ^     ^       ^
+      //         s       m     e              s     m       e
+      s = s1
+      if s == m { m = m1 }
+    }
+    
+    return ret
+  }
+  
+  /// Rotates the elements of this collection so that the element at the
+  /// specified index becomes the start of the collection.
+  ///
+  /// Rotating a collection is equivalent to breaking the collection into two
+  /// sections at the index `newStart`, and then swapping those two sections.
+  /// In this example, the `numbers` array is rotated so that the element at
+  /// index `3` (`40`) is first:
+  ///
+  ///     var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
+  ///     let oldStart = numbers.rotate(toStartAt: 3)
+  ///     // numbers == [40, 50, 60, 70, 80, 10, 20, 30]
+  ///     // numbers[oldStart] == 10
+  ///
+  /// - Parameter newStart: The index of the element that should be first after
+  ///   rotating.
+  /// - Returns: The new index of the element that was first pre-rotation.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the collection.
+  @inlinable
+  @discardableResult
+  public mutating func rotate(toStartAt newStart: Index) -> Index {
+    rotate(subrange: startIndex..<endIndex, toStartAt: newStart)
+  }
+}
+
+extension MutableCollection where Self: BidirectionalCollection {
+  /// Rotates the elements within the given subrange so that the element at the
+  /// specified index becomes the start of the subrange.
+  ///
+  /// Rotating a collection is equivalent to breaking the collection into two
+  /// sections at the index `newStart`, and then swapping those two sections.
+  /// In this example, the `numbers` array is rotated so that the element at
+  /// index `3` (`40`) is first:
+  ///
+  ///     var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
+  ///     let oldStart = numbers.rotate(subrange: 0..<4, toStartAt: 2)
+  ///     // numbers == [30, 40, 10, 20, 50, 60, 70, 80]
+  ///     // numbers[oldStart] == 10
+  ///
+  /// - Parameters:
+  ///   - subrange: The subrange of this collection to rotate.
+  ///   - newStart: The index of the element that should be at the start of
+  ///     `subrange` after rotating.
+  /// - Returns: The new index of the element that was at the start of
+  ///   `subrange` pre-rotation.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of `subrange`.
+  @inlinable
+  @discardableResult
+  public mutating func rotate(
+    subrange: Range<Index>,
+    toStartAt newStart: Index
+  ) -> Index {
+    reverse(subrange: subrange.lowerBound..<newStart)
+    reverse(subrange: newStart..<subrange.upperBound)
+    let (p, q) = _reverse(subrange: subrange, until: newStart)
+    reverse(subrange: p..<q)
+    return newStart == p ? q : p
+  }
+
+  /// Rotates the elements of this collection so that the element at the
+  /// specified index becomes the start of the collection.
+  ///
+  /// Rotating a collection is equivalent to breaking the collection into two
+  /// sections at the index `newStart`, and then swapping those two sections. In
+  /// this example, the `numbers` array is rotated so that the element at index
+  /// `3` (`40`) is first:
+  ///
+  ///     var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
+  ///     let oldStart = numbers.rotate(toStartAt: 3)
+  ///     // numbers == [40, 50, 60, 70, 80, 10, 20, 30]
+  ///     // numbers[oldStart] == 10
+  ///
+  /// - Parameter newStart: The index of the element that should be first after
+  ///   rotating.
+  /// - Returns: The new index of the element that was first pre-rotation.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the collection.
+  @inlinable
+  @discardableResult
+  public mutating func rotate(toStartAt newStart: Index) -> Index {
+    rotate(subrange: startIndex..<endIndex, toStartAt: newStart)
+  }
+}

+ 756 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Split.swift

@@ -0,0 +1,756 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2021 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// SplitSequence
+//===----------------------------------------------------------------------===//
+
+/// A sequence that lazily splits a base sequence into subsequences separated by
+/// elements that satisfy the given `whereSeparator` predicate.
+///
+/// - Note: This type is the result of
+///
+///     x.split(maxSplits:omittingEmptySubsequences:whereSeparator)
+///     x.split(separator:maxSplits:omittingEmptySubsequences)
+///
+///   where `x` conforms to `LazySequenceProtocol`.
+public struct SplitSequence<Base: Sequence> {
+  @usableFromInline
+  internal let base: Base
+
+  @usableFromInline
+  internal let isSeparator: (Base.Element) -> Bool
+
+  @usableFromInline
+  internal let maxSplits: Int
+
+  @usableFromInline
+  internal let omittingEmptySubsequences: Bool
+
+  @inlinable
+  internal init(
+    base: Base,
+    isSeparator: @escaping (Base.Element) -> Bool,
+    maxSplits: Int,
+    omittingEmptySubsequences: Bool
+  ) {
+    self.base = base
+    self.isSeparator = isSeparator
+    self.maxSplits = maxSplits
+    self.omittingEmptySubsequences = omittingEmptySubsequences
+  }
+}
+
+extension SplitSequence: Sequence {
+  public struct Iterator {
+    public typealias Element = [Base.Element]
+
+    @usableFromInline
+    internal var base: Base.Iterator
+
+    @usableFromInline
+    internal let isSeparator: (Base.Element) -> Bool
+
+    @usableFromInline
+    internal let maxSplits: Int
+
+    @usableFromInline
+    internal let omittingEmptySubsequences: Bool
+
+    /// The number of splits performed.
+    @usableFromInline
+    internal var splitCount = 0
+
+    /// The number of subsequences returned.
+    @usableFromInline
+    internal var sequenceLength = 0
+
+    @inlinable
+    internal init(
+      base: Base.Iterator,
+      whereSeparator: @escaping (Base.Element) -> Bool,
+      maxSplits: Int,
+      omittingEmptySubsequences: Bool
+    ) {
+      self.base = base
+      self.isSeparator = whereSeparator
+      self.maxSplits = maxSplits
+      self.omittingEmptySubsequences = omittingEmptySubsequences
+    }
+  }
+  
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(
+      base: base.makeIterator(),
+      whereSeparator: self.isSeparator,
+      maxSplits: self.maxSplits,
+      omittingEmptySubsequences: self.omittingEmptySubsequences
+    )
+  }
+}
+
+extension SplitSequence.Iterator: IteratorProtocol {
+  @inlinable
+  public mutating func next() -> Element? {
+    var currentElement = base.next()
+    var subsequence: Element = []
+
+    // Add the next elements of the base sequence to this subsequence, until we
+    // reach a separator, unless we've already split the maximum number of
+    // times. In all cases, stop at the end of the base sequence.
+    while currentElement != nil {
+      if splitCount < maxSplits && isSeparator(currentElement!) {
+        if omittingEmptySubsequences && subsequence.isEmpty {
+          // Keep going if we don't want to return an empty subsequence.
+          currentElement = base.next()
+          continue
+        } else {
+          splitCount += 1
+          break
+        }
+      } else {
+        subsequence.append(currentElement!)
+        currentElement = base.next()
+      }
+    }
+
+    // We're done iterating when we've reached the end of the base sequence,
+    // and we've either returned the maximum number of subsequences (one more
+    // than the number of separators), or the only subsequence left to return is
+    // empty and we're omitting those.
+    if currentElement == nil
+      && (sequenceLength == splitCount + 1
+        || omittingEmptySubsequences && subsequence.isEmpty)
+    {
+      return nil
+    } else {
+      sequenceLength += 1
+      return subsequence
+    }
+  }
+}
+
+extension SplitSequence: LazySequenceProtocol {}
+
+extension LazySequenceProtocol {
+  /// Lazily returns the longest possible subsequences of the sequence, in
+  /// order, that don't contain elements satisfying the given predicate.
+  ///
+  /// The resulting lazy sequence consists of at most `maxSplits + 1`
+  /// subsequences. Elements that are used to split the sequence are not
+  /// returned as part of any subsequence (except possibly the last one, in the
+  /// case where `maxSplits` is less than the number of separators in the
+  /// sequence).
+  ///
+  /// The following examples show the effects of the `maxSplits` and
+  /// `omittingEmptySubsequences` parameters when lazily splitting a sequence of
+  /// integers using a closure that matches numbers evenly divisible by 3 or 5.
+  /// The first use of `split` returns each subsequence that was originally
+  /// separated by one or more such numbers.
+  ///
+  ///     let numbers = stride(from: 1, through: 16, by: 1)
+  ///     for subsequence in numbers.lazy.split(
+  ///       whereSeparator: { $0 % 3 == 0 || $0 % 5 == 0 }
+  ///     ) {
+  ///       print(subsequence)
+  ///     }
+  ///     /* Prints:
+  ///     [1, 2]
+  ///     [4]
+  ///     [7, 8]
+  ///     [11]
+  ///     [13, 14]
+  ///     [16]
+  ///     */
+  ///
+  /// The second example passes `1` for the `maxSplits` parameter, so the
+  /// original sequence is split just once, into two subsequences.
+  ///
+  ///     for subsequence in numbers.lazy.split(
+  ///       maxSplits: 1,
+  ///       whereSeparator: { $0 % 3 == 0 || $0 % 5 == 0 }
+  ///     ) {
+  ///       print(subsequence)
+  ///     }
+  ///     /* Prints:
+  ///     [1, 2]
+  ///     [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
+  ///     */
+  ///
+  /// The final example passes `false` for the `omittingEmptySubsequences`
+  /// parameter, so the sequence of returned subsequences contains empty
+  /// subsequences where numbers evenly divisible by 3 or 5 were repeated.
+  ///
+  ///     for subsequence in numbers.lazy.split(
+  ///         omittingEmptySubsequences: false,
+  ///         whereSeparator: { $0 % 3 == 0 || $0 % 5 == 0 }
+  ///     ) {
+  ///       print(subsequence)
+  ///     }
+  ///     /* Prints:
+  ///     [1, 2]
+  ///     [4]
+  ///     []
+  ///     [7, 8]
+  ///     []
+  ///     [11]
+  ///     [13, 14]
+  ///     [16]
+  ///     */
+  ///
+  /// - Parameters:
+  ///   - maxSplits: The maximum number of times to split the sequence, or
+  ///     one less than the number of subsequences to return. If
+  ///     `maxSplits + 1` subsequences are returned, the last one is a suffix
+  ///     of the original sequence containing the remaining elements.
+  ///     `maxSplits` must be greater than or equal to zero. The default value
+  ///     is `Int.max`.
+  ///   - omittingEmptySubsequences: If `false`, an empty subsequence is
+  ///     returned in the result for each pair of consecutive elements
+  ///     satisfying the `isSeparator` predicate and for each element at the
+  ///     start or end of the sequence satisfying the `isSeparator`
+  ///     predicate. The default value is `true`.
+  ///   - whereSeparator: A closure that takes an element as an argument and
+  ///     returns a Boolean value indicating whether the sequence should be
+  ///     split at that element.
+  /// - Returns: A lazy sequence of subsequences, split from this sequence's
+  ///   elements.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the sequence.
+  @inlinable
+  public func split(
+    maxSplits: Int = Int.max,
+    omittingEmptySubsequences: Bool = true,
+    whereSeparator isSeparator: @escaping (Element) -> Bool
+  ) -> SplitSequence<Elements> {
+    precondition(maxSplits >= 0, "Must take zero or more splits")
+
+    return SplitSequence(
+      base: elements,
+      isSeparator: isSeparator,
+      maxSplits: maxSplits,
+      omittingEmptySubsequences: omittingEmptySubsequences
+    )
+  }
+}
+
+extension LazySequenceProtocol where Element: Equatable {
+  /// Lazily returns the longest possible subsequences of the sequence, in
+  /// order, around elements equal to the given element.
+  ///
+  /// The resulting lazy sequence consists of at most `maxSplits + 1`
+  /// subsequences. Elements that are used to split the sequence are not
+  /// returned as part of any subsequence (except possibly the last one, in the
+  /// case where `maxSplits` is less than the number of separators in the
+  /// sequence).
+  ///
+  /// The following examples show the effects of the `maxSplits` and
+  /// `omittingEmptySubsequences` parameters when splitting a sequence of
+  /// integers at each zero (`0`). The first use of `split` returns each
+  /// subsequence that was originally separated by one or more zeros.
+  ///
+  ///     let numbers = AnySequence([1, 2, 0, 3, 4, 0, 0, 5])
+  ///     for subsequence in numbers.lazy.split(separator: 0) {
+  ///       print(subsequence)
+  ///     }
+  ///     /* Prints:
+  ///     [1, 2]
+  ///     [3, 4]
+  ///     [5]
+  ///     */
+  ///
+  /// The second example passes `1` for the `maxSplits` parameter, so the
+  /// original sequence is split just once, into two subsequences.
+  ///
+  ///     for subsequence in numbers.lazy.split(
+  ///         separator: 0,
+  ///         maxSplits: 1
+  ///     ) {
+  ///       print(subsequence)
+  ///     }
+  ///     /* Prints:
+  ///     [1, 2]
+  ///     [3, 4, 0, 0, 5]
+  ///     */
+  ///
+  /// The final example passes `false` for the `omittingEmptySubsequences`
+  /// parameter, so the sequence of returned subsequences contains empty
+  /// subsequences where zeros were repeated.
+  ///
+  ///     for subsequence in numbers.lazy.split(
+  ///         separator: 0,
+  ///         omittingEmptySubsequences: false
+  ///     ) {
+  ///       print(subsequence)
+  ///     }
+  ///     /* Prints:
+  ///     [1, 2]
+  ///     [3, 4]
+  ///     []
+  ///     [5]
+  ///     */
+  ///
+  /// - Parameters:
+  ///   - separator: The element that should be split upon.
+  ///   - maxSplits: The maximum number of times to split the sequence, or
+  ///     one less than the number of subsequences to return. If
+  ///     `maxSplits + 1` subsequences are returned, the last one is a suffix
+  ///     of the original sequence containing the remaining elements.
+  ///     `maxSplits` must be greater than or equal to zero. The default value
+  ///     is `Int.max`.
+  ///   - omittingEmptySubsequences: If `false`, an empty subsequence is
+  ///     returned in the result for each consecutive pair of `separator`
+  ///     elements in the sequence and for each instance of `separator` at
+  ///     the start or end of the sequence. If `true`, only nonempty
+  ///     subsequences are returned. The default value is `true`.
+  /// - Returns: A lazy sequence of subsequences, split from this sequence's
+  ///   elements.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the sequence.
+  @inlinable
+  public func split(
+    separator: Element,
+    maxSplits: Int = Int.max,
+    omittingEmptySubsequences: Bool = true
+  ) -> SplitSequence<Elements> {
+    precondition(maxSplits >= 0, "Must take zero or more splits")
+
+    return SplitSequence(
+      base: elements,
+      isSeparator: { $0 == separator },
+      maxSplits: maxSplits,
+      omittingEmptySubsequences: omittingEmptySubsequences
+    )
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// SplitCollection
+//===----------------------------------------------------------------------===//
+
+/// A collection that lazily splits a base collection into subsequences
+/// separated by elements that satisfy the given `whereSeparator` predicate.
+///
+/// - Note: This type is the result of
+///
+///     x.split(maxSplits:omittingEmptySubsequences:whereSeparator)
+///     x.split(separator:maxSplits:omittingEmptySubsequences)
+///
+///   where `x` conforms to `LazySequenceProtocol` and `Collection`.
+public struct SplitCollection<Base: Collection> {
+  @usableFromInline
+  internal let base: Base
+
+  @usableFromInline
+  internal let isSeparator: (Base.Element) -> Bool
+
+  @usableFromInline
+  internal let maxSplits: Int
+
+  @usableFromInline
+  internal let omittingEmptySubsequences: Bool
+
+  @usableFromInline
+  internal var _startIndex: Index
+
+  @inlinable
+  internal init(
+    base: Base,
+    isSeparator: @escaping (Base.Element) -> Bool,
+    maxSplits: Int,
+    omittingEmptySubsequences: Bool
+  ) {
+    self.base = base
+    self.isSeparator = isSeparator
+    self.maxSplits = maxSplits
+    self.omittingEmptySubsequences = omittingEmptySubsequences
+
+    // We precalculate `startIndex`. There are three possibilities:
+    // 1. `base` is empty and we're _not_ omitting empty subsequences, in which
+    // case the following index describes the sole element of this collection;
+    self._startIndex = Index(
+      baseRange: base.startIndex..<base.startIndex,
+      sequenceLength: 1,
+      splitCount: 0
+    )
+    if base.isEmpty {
+      if omittingEmptySubsequences {
+        // 2. `base` is empty and we _are_ omitting empty subsequences, so this
+        // collection has no elements;
+        _startIndex = endIndex
+      }
+    } else {
+      // 3. `base` isn't empty, so we must iterate it to determine the start
+      // index.
+      _startIndex = indexForSubsequence(
+        atOrAfter: base.startIndex,
+        sequenceLength: 0,
+        splitCount: 0
+      )
+    }
+  }
+}
+
+extension SplitCollection: Collection {
+  /// Position of a subsequence in a split collection.
+  public struct Index: Comparable {
+    /// The range corresponding to the subsequence at this position.
+    @usableFromInline
+    internal let baseRange: Range<Base.Index>
+
+    /// The number of subsequences up to and including this position in the
+    /// collection.
+    @usableFromInline
+    internal let sequenceLength: Int
+
+    /// The number splits performed up to and including this position in the
+    /// collection.
+    @usableFromInline
+    internal let splitCount: Int
+
+    @inlinable
+    internal init(
+      baseRange: Range<Base.Index>,
+      sequenceLength: Int,
+      splitCount: Int
+    ) {
+      self.baseRange = baseRange
+      self.sequenceLength = sequenceLength
+      self.splitCount = splitCount
+    }
+
+    @inlinable
+    public static func == (lhs: Index, rhs: Index) -> Bool {
+      // `sequenceLength` is equivalent to the index's 1-based position in the
+      // collection of indices.
+      lhs.sequenceLength == rhs.sequenceLength
+    }
+
+    @inlinable
+    public static func < (lhs: Index, rhs: Index) -> Bool {
+      lhs.sequenceLength < rhs.sequenceLength
+    }
+  }
+
+  /// Returns the index of the subsequence starting at or after the given base
+  /// collection index.
+  @inlinable
+  internal func indexForSubsequence(
+    atOrAfter lowerBound: Base.Index,
+    sequenceLength: Int,
+    splitCount: Int
+  ) -> Index {
+    var start = lowerBound
+    // If we don't have any more splits to do (which we'll determine shortly),
+    // the end of this subsequence will be the end of the base collection.
+    var end = base.endIndex
+
+    if splitCount < maxSplits {
+      // The non-inclusive end of this subsequence is marked by the next
+      // separator, or the end of the base collection.
+      end =
+        base[start...].firstIndex(where: isSeparator)
+        ?? base.endIndex
+
+      if base[start..<end].isEmpty {
+        if omittingEmptySubsequences {
+          // Find the next subsequence of non-separators.
+          start =
+            base[end...].firstIndex(where: { !isSeparator($0) })
+            ?? base.endIndex
+          if start == base.endIndex {
+            // No non-separators left in the base collection. We're done.
+            return endIndex
+          }
+          end = base[start...].firstIndex(where: isSeparator) ?? base.endIndex
+        }
+      }
+    }
+
+    var updatedSplitCount = splitCount
+    if end != base.endIndex {
+      // This subsequence ends on a separator (and perhaps includes other
+      // separators, if we're omitting empty subsequences), so we've performed
+      // another split.
+      updatedSplitCount += 1
+    }
+
+    return Index(
+      baseRange: start..<end,
+      sequenceLength: sequenceLength + 1,
+      splitCount: updatedSplitCount
+    )
+  }
+
+  @inlinable
+  public var startIndex: Index {
+    _startIndex
+  }
+
+  @inlinable
+  public var endIndex: Index {
+    Index(
+      baseRange: base.endIndex..<base.endIndex,
+      sequenceLength: Int.max,
+      splitCount: Int.max
+    )
+  }
+
+  @inlinable
+  public func index(after i: Index) -> Index {
+    precondition(i != endIndex, "Can't advance past endIndex")
+
+    var subsequenceStart = i.baseRange.upperBound
+    if subsequenceStart < base.endIndex {
+      // If we're not already at the end of the base collection, the previous
+      // susequence ended with a separator. Start searching for the next
+      // subsequence at the following element.
+      subsequenceStart = base.index(after: i.baseRange.upperBound)
+    }
+
+    guard subsequenceStart != base.endIndex else {
+      if !omittingEmptySubsequences
+        && i.sequenceLength < i.splitCount + 1
+      {
+        // The base collection ended with a separator, so we need to emit one
+        // more empty subsequence. This one differs from `endIndex` in its
+        // `sequenceLength` (except in an extreme edge case!), which is the
+        // sole property tested for equality and comparison.
+        return Index(
+          baseRange: base.endIndex..<base.endIndex,
+          sequenceLength: i.sequenceLength + 1,
+          splitCount: i.splitCount
+        )
+      } else {
+        return endIndex
+      }
+    }
+
+    return indexForSubsequence(
+      atOrAfter: subsequenceStart,
+      sequenceLength: i.sequenceLength,
+      splitCount: i.splitCount
+    )
+  }
+
+  @inlinable
+  public subscript(position: Index) -> Base.SubSequence {
+    precondition(position != endIndex, "Can't subscript using endIndex")
+    return base[position.baseRange]
+  }
+}
+
+extension SplitCollection.Index: Hashable {
+  @inlinable
+  public func hash(into hasher: inout Hasher) {
+    hasher.combine(sequenceLength)
+  }
+}
+
+extension SplitCollection: LazyCollectionProtocol {}
+
+extension LazySequenceProtocol where Self: Collection, Elements: Collection {
+  /// Lazily returns the longest possible subsequences of the collection, in
+  /// order, that don't contain elements satisfying the given predicate.
+  ///
+  /// The resulting lazy collection consists of at most `maxSplits + 1`
+  /// subsequences. Elements that are used to split the collection are not
+  /// returned as part of any subsequence (except possibly the last one, in the
+  /// case where `maxSplits` is less than the number of separators in the
+  /// collection).
+  ///
+  /// The following examples show the effects of the `maxSplits` and
+  /// `omittingEmptySubsequences` parameters when lazily splitting a string
+  /// using a closure that matches spaces. The first use of `split` returns each
+  /// word that was originally separated by one or more spaces.
+  ///
+  ///     let line = "BLANCHE:   I don't want realism. I want magic!"
+  ///     for spaceless in line.lazy.split(whereSeparator: { $0 == " " }) {
+  ///       print(spaceless)
+  ///     }
+  ///     // Prints
+  ///     // BLANCHE:
+  ///     // I
+  ///     // don't
+  ///     // want
+  ///     // realism.
+  ///     // I
+  ///     // want
+  ///     // magic!
+  ///
+  /// The second example passes `1` for the `maxSplits` parameter, so the
+  /// original string is split just once, into two new strings.
+  ///
+  ///     for spaceless in line.lazy.split(
+  ///       maxSplits: 1,
+  ///       whereSeparator: { $0 == " " }
+  ///     ) {
+  ///       print(spaceless)
+  ///     }
+  ///     // Prints
+  ///     // BLANCHE:
+  ///     // I don't want realism. I want magic!
+  ///
+  /// The final example passes `false` for the `omittingEmptySubsequences`
+  /// parameter, so the returned array contains empty strings where spaces
+  /// were repeated.
+  ///
+  ///     for spaceless in line.lazy.split(
+  ///       omittingEmptySubsequences: false,
+  ///       whereSeparator: { $0 == " " }
+  ///     ) {
+  ///       print(spaceless)
+  ///     }
+  ///     // Prints
+  ///     // BLANCHE:
+  ///     //
+  ///     //
+  ///     // I
+  ///     // don't
+  ///     // want
+  ///     // realism.
+  ///     // I
+  ///     // want
+  ///     // magic!
+  ///
+  /// - Parameters:
+  ///   - maxSplits: The maximum number of times to split the collection, or
+  ///     one less than the number of subsequences to return. If
+  ///     `maxSplits + 1` subsequences are returned, the last one is a suffix
+  ///     of the original collection containing the remaining elements.
+  ///     `maxSplits` must be greater than or equal to zero. The default value
+  ///     is `Int.max`.
+  ///   - omittingEmptySubsequences: If `false`, an empty subsequence is
+  ///     returned in the result for each pair of consecutive elements
+  ///     satisfying the `isSeparator` predicate and for each element at the
+  ///     start or end of the collection satisfying the `isSeparator`
+  ///     predicate. The default value is `true`.
+  ///   - whereSeparator: A closure that takes an element as an argument and
+  ///     returns a Boolean value indicating whether the collection should be
+  ///     split at that element.
+  /// - Returns: A lazy collection of subsequences, split from this collection's
+  ///   elements.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the collection.
+  @inlinable
+  public func split(
+    maxSplits: Int = Int.max,
+    omittingEmptySubsequences: Bool = true,
+    whereSeparator isSeparator: @escaping (Element) -> Bool
+  ) -> SplitCollection<Elements> {
+    precondition(maxSplits >= 0, "Must take zero or more splits")
+
+    return SplitCollection(
+      base: elements,
+      isSeparator: isSeparator,
+      maxSplits: maxSplits,
+      omittingEmptySubsequences: omittingEmptySubsequences
+    )
+  }
+}
+
+extension LazySequenceProtocol
+  where Self: Collection, Elements: Collection, Element: Equatable
+{
+  /// Lazily returns the longest possible subsequences of the collection, in
+  /// order, around elements equal to the given element.
+  ///
+  /// The resulting lazy collection consists of at most `maxSplits + 1`
+  /// subsequences. Elements that are used to split the collection are not
+  /// returned as part of any subsequence (except possibly the last one, in the
+  /// case where `maxSplits` is less than the number of separators in the
+  /// collection).
+  ///
+  /// The following examples show the effects of the `maxSplits` and
+  /// `omittingEmptySubsequences` parameters when splitting a string at each
+  /// space character (" "). The first use of `split` returns each word that
+  /// was originally separated by one or more spaces.
+  ///
+  ///     let line = "BLANCHE:   I don't want realism. I want magic!"
+  ///     for spaceless in line.lazy.split(separator: " ") {
+  ///       print(spaceless)
+  ///     }
+  ///     // Prints
+  ///     // BLANCHE:
+  ///     // I
+  ///     // don't
+  ///     // want
+  ///     // realism.
+  ///     // I
+  ///     // want
+  ///     // magic!
+  ///
+  /// The second example passes `1` for the `maxSplits` parameter, so the
+  /// original string is split just once, into two new strings.
+  ///
+  ///     for spaceless in line.lazy.split(separator: " ", maxSplits: 1) {
+  ///       print(spaceless)
+  ///     }
+  ///     // Prints
+  ///     // BLANCHE:
+  ///     // I don't want realism. I want magic!
+  ///
+  /// The final example passes `false` for the `omittingEmptySubsequences`
+  /// parameter, so the returned array contains empty strings where spaces
+  /// were repeated.
+  ///
+  ///     for spaceless in line.lazy.split(
+  ///       separator: " ",
+  ///       omittingEmptySubsequences: false
+  ///     ) {
+  ///       print(spaceless)
+  ///     }
+  ///     // Prints
+  ///     // BLANCHE:
+  ///     //
+  ///     //
+  ///     // I
+  ///     // don't
+  ///     // want
+  ///     // realism.
+  ///     // I
+  ///     // want
+  ///     // magic!
+  ///
+  /// - Parameters:
+  ///   - separator: The element that should be split upon.
+  ///   - maxSplits: The maximum number of times to split the collection, or
+  ///     one less than the number of subsequences to return. If
+  ///     `maxSplits + 1` subsequences are returned, the last one is a suffix
+  ///     of the original collection containing the remaining elements.
+  ///     `maxSplits` must be greater than or equal to zero. The default value
+  ///     is `Int.max`.
+  ///   - omittingEmptySubsequences: If `false`, an empty subsequence is
+  ///     returned in the result for each consecutive pair of `separator`
+  ///     elements in the collection and for each instance of `separator` at
+  ///     the start or end of the collection. If `true`, only nonempty
+  ///     subsequences are returned. The default value is `true`.
+  /// - Returns: A lazy collection of subsequences split from this collection's
+  ///   elements.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the collection.
+  @inlinable
+  public func split(
+    separator: Element,
+    maxSplits: Int = Int.max,
+    omittingEmptySubsequences: Bool = true
+  ) -> SplitCollection<Elements> {
+    precondition(maxSplits >= 0, "Must take zero or more splits")
+
+    return SplitCollection(
+      base: elements,
+      isSeparator: { $0 == separator },
+      maxSplits: maxSplits,
+      omittingEmptySubsequences: omittingEmptySubsequences
+    )
+  }
+}

+ 283 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Stride.swift

@@ -0,0 +1,283 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// striding(by:)
+//===----------------------------------------------------------------------===//
+
+extension Sequence {
+  /// Returns a sequence stepping through the elements every `step` starting at
+  /// the first value. Any remainders of the stride will be trimmed.
+  ///
+  ///     (0...10).striding(by: 2) // == [0, 2, 4, 6, 8, 10]
+  ///     (0...10).striding(by: 3) // == [0, 3, 6, 9]
+  ///
+  /// - Complexity: O(1). Access to successive values is O(k) where _k_ is the
+  ///   striding `step`.
+  ///
+  /// - Parameter step: The amount to step with each iteration.
+  /// - Returns: Returns a sequence for stepping through the elements by the
+  ///   specified amount.
+  @inlinable
+  public func striding(by step: Int) -> StridingSequence<Self> {
+    StridingSequence(base: self, stride: step)
+  }
+}
+
+extension Collection {
+  /// Returns a sequence stepping through the elements every `step` starting at
+  /// the first value. Any remainders of the stride will be trimmed.
+  ///
+  ///     (0...10).striding(by: 2) // == [0, 2, 4, 6, 8, 10]
+  ///     (0...10).striding(by: 3) // == [0, 3, 6, 9]
+  ///
+  /// - Complexity: O(1). Access to successive values is O(1) if the collection
+  ///   conforms to `RandomAccessCollection`; otherwise, O(_k_), where _k_ is
+  ///   the striding `step`.
+  ///
+  /// - Parameter step: The amount to step with each iteration.
+  /// - Returns: Returns a collection for stepping through the elements by the
+  ///   specified amount.
+  @inlinable
+  public func striding(by step: Int) -> StridingCollection<Self> {
+    StridingCollection(base: self, stride: step)
+  }
+}
+
+/// A wrapper that strides over a base sequence.
+public struct StridingSequence<Base: Sequence> {
+  @usableFromInline
+  internal let base: Base
+  
+  @usableFromInline
+  internal let stride: Int
+  
+  @inlinable
+  internal init(base: Base, stride: Int) {
+    precondition(stride > 0, "Stride must be greater than zero")
+    self.base = base
+    self.stride = stride
+  }
+}
+
+extension StridingSequence {
+  @inlinable
+  public func striding(by step: Int) -> Self {
+    Self(base: base, stride: stride * step)
+  }
+}
+
+extension StridingSequence: Sequence {
+  /// An iterator over a `StridingSequence` instance.
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal var iterator: Base.Iterator
+    
+    @usableFromInline
+    internal let stride: Int
+    
+    @usableFromInline
+    internal var striding: Bool = false
+    
+    @inlinable
+    internal init(iterator: Base.Iterator, stride: Int) {
+      self.iterator = iterator
+      self.stride = stride
+    }
+    
+    @inlinable
+    public mutating func next() -> Base.Element? {
+      guard striding else {
+        striding = true
+        return iterator.next()
+      }
+      for _ in 0..<stride - 1 {
+        guard iterator.next() != nil else { break }
+      }
+      return iterator.next()
+    }
+  }
+  
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(iterator: base.makeIterator(), stride: stride)
+  }
+}
+
+extension StridingSequence: LazySequenceProtocol
+  where Base: LazySequenceProtocol {}
+
+/// A wrapper that strides over a base collection.
+public struct StridingCollection<Base: Collection> {
+  @usableFromInline
+  internal let base: Base
+  
+  @usableFromInline
+  internal let stride: Int
+  
+  @inlinable
+  internal init(base: Base, stride: Int) {
+    precondition(stride > 0, "striding must be greater than zero")
+    self.base = base
+    self.stride = stride
+  }
+}
+
+extension StridingCollection {
+  @inlinable
+  public func striding(by step: Int) -> Self {
+    Self(base: base, stride: stride * step)
+  }
+}
+
+extension StridingCollection: Collection {
+  /// A position in a `StridingCollection` instance.
+  public struct Index: Comparable {
+    @usableFromInline
+    internal let base: Base.Index
+    
+    @usableFromInline
+    internal init(_ base: Base.Index) {
+      self.base = base
+    }
+    
+    @inlinable
+    public static func < (lhs: Index, rhs: Index) -> Bool {
+      lhs.base < rhs.base
+    }
+  }
+  
+  @inlinable
+  public var startIndex: Index {
+    Index(base.startIndex)
+  }
+  
+  @inlinable
+  public var endIndex: Index {
+    Index(base.endIndex)
+  }
+  
+  @inlinable
+  public subscript(i: Index) -> Base.Element {
+    base[i.base]
+  }
+  
+  @inlinable
+  public func index(after i: Index) -> Index {
+    precondition(i.base != base.endIndex, "Advancing past end index")
+    return index(i, offsetBy: 1)
+  }
+  
+  @inlinable
+  public func index(
+    _ i: Index,
+    offsetBy n: Int,
+    limitedBy limit: Index
+  ) -> Index? {
+    guard n != 0 else { return i }
+    guard limit != i else { return nil }
+    
+    return n > 0
+      ? offsetForward(i, offsetBy: n, limitedBy: limit)
+      : offsetBackward(i, offsetBy: -n, limitedBy: limit)
+  }
+  
+  @inlinable
+  internal func offsetForward(
+    _ i: Index,
+    offsetBy n: Int,
+    limitedBy limit: Index
+  ) -> Index? {
+    if limit < i {
+      if let idx = base.index(
+        i.base,
+        offsetBy: n * stride,
+        limitedBy: base.endIndex
+      ) {
+        return Index(idx)
+      } else {
+        assert(distance(from: i, to: endIndex) == n, "Advancing past end index")
+        return endIndex
+      }
+    } else if let idx = base.index(
+      i.base,
+      offsetBy: n * stride,
+      limitedBy: limit.base
+    ) {
+      return Index(idx)
+    } else {
+      return distance(from: i, to: limit) == n
+        ? endIndex
+        : nil
+    }
+  }
+  
+  @inlinable
+  internal func offsetBackward(
+    _ i: Index,
+    offsetBy n: Int,
+    limitedBy limit: Index
+  ) -> Index? {
+    // We typically use the ternary operator but this significantly increases
+    // compile times when using Swift 5.3.2
+    // https://github.com/apple/swift-algorithms/issues/146
+    let distance: Int
+    if i == endIndex {
+      distance = -((base.count - 1) % stride + 1) + (n - 1) * -stride
+    } else {
+      distance = n * -stride
+    }
+    return base.index(
+        i.base,
+        offsetBy: distance,
+        limitedBy: limit.base
+    ).map(Index.init)
+  }
+  
+  @inlinable
+  public var count: Int {
+    base.isEmpty ? 0 : (base.count - 1) / stride + 1
+  }
+  
+  @inlinable
+  public func distance(from start: Index, to end: Index) -> Int {
+    let distance = base.distance(from: start.base, to: end.base)
+    return distance / stride + (distance % stride).signum()
+  }
+  
+  @inlinable
+  public func index(_ i: Index, offsetBy distance: Int) -> Index {
+    precondition(distance <= 0 || i.base != base.endIndex, "Advancing past end index")
+    precondition(distance >= 0 || i.base != base.startIndex, "Incrementing past start index")
+    let limit = distance > 0 ? endIndex : startIndex
+    let idx = index(i, offsetBy: distance, limitedBy: limit)
+    precondition(idx != nil, "The distance \(distance) is not valid for this collection")
+    return idx!
+  }
+}
+
+extension StridingCollection: BidirectionalCollection
+  where Base: RandomAccessCollection {
+  
+  @inlinable
+  public func index(before i: Index) -> Index {
+    precondition(i.base != base.startIndex, "Incrementing past start index")
+    return index(i, offsetBy: -1)
+  }
+}
+
+extension StridingCollection: RandomAccessCollection
+  where Base: RandomAccessCollection {}
+
+extension StridingCollection: LazySequenceProtocol, LazyCollectionProtocol
+  where Base: LazySequenceProtocol {}
+
+extension StridingCollection.Index: Hashable where Base.Index: Hashable {}

+ 88 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Suffix.swift

@@ -0,0 +1,88 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2021 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// suffix(while:)
+//===----------------------------------------------------------------------===//
+
+extension BidirectionalCollection {
+  /// Returns a subsequence containing the elements from the end until
+  /// `predicate` returns `false` and skipping the remaining elements.
+  ///
+  /// - Parameter predicate: A closure that takes an element of the sequence as
+  ///   its argument and returns `true` if the element should be included or
+  ///   `false` if it should be excluded. Once the predicate returns `false` it
+  ///   will not be called again.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the collection.
+  @inlinable
+  public func suffix(
+    while predicate: (Element) throws -> Bool
+  ) rethrows -> SubSequence {
+    try self[startOfSuffix(while: predicate)...]
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// endOfPrefix(while:)
+//===----------------------------------------------------------------------===//
+
+extension Collection {
+  /// Returns the exclusive upper bound of the prefix of elements that satisfy
+  /// the predicate.
+  ///
+  /// - Parameter predicate: A closure that takes an element of the collection
+  ///   as its argument and returns `true` if the element is part of the prefix
+  ///   or `false` if it is not. Once the predicate returns `false` it will not
+  ///   be called again.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the collection.
+  @inlinable
+  internal func endOfPrefix(
+    while predicate: (Element) throws -> Bool
+  ) rethrows -> Index {
+    var index = startIndex
+    while try index != endIndex && predicate(self[index]) {
+      formIndex(after: &index)
+    }
+    return index
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// startOfSuffix(while:)
+//===----------------------------------------------------------------------===//
+
+extension BidirectionalCollection {
+  /// Returns the inclusive lower bound of the suffix of elements that satisfy
+  /// the predicate.
+  ///
+  /// - Parameter predicate: A closure that takes an element of the collection
+  ///   as its argument and returns `true` if the element is part of the suffix
+  ///   or `false` if it is not. Once the predicate returns `false` it will not
+  ///   be called again.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the collection.
+  @inlinable
+  internal func startOfSuffix(
+    while predicate: (Element) throws -> Bool
+  ) rethrows -> Index {
+    var index = endIndex
+    while index != startIndex {
+      let after = index
+      formIndex(before: &index)
+      if try !predicate(self[index]) {
+        return after
+      }
+    }
+    return index
+  }
+}

+ 240 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Trim.swift

@@ -0,0 +1,240 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+
+//===----------------------------------------------------------------------===//
+// trimmingPrefix(while:)
+//===----------------------------------------------------------------------===//
+
+extension Collection {
+  /// Returns a `SubSequence` formed by discarding all elements at the start of
+  /// the collection which satisfy the given predicate.
+  ///
+  /// This example uses `trimmingPrefix(while:)` to get a substring without the
+  /// white space at the beginning of the string:
+  ///
+  ///     let myString = "  hello, world  "
+  ///     print(myString.trimmingPrefix(while: \.isWhitespace)) // "hello, world  "
+  ///
+  /// - Parameter predicate: A closure which determines if the element should be
+  ///   omitted from the resulting slice.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of this collection.
+  ///
+  @inlinable
+  public func trimmingPrefix(
+    while predicate: (Element) throws -> Bool
+  ) rethrows -> SubSequence {
+    let start = try endOfPrefix(while: predicate)
+    return self[start...]
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// trimPrefix(while:)
+//===----------------------------------------------------------------------===//
+
+extension Collection where Self: RangeReplaceableCollection {
+  /// Mutates a `Collection` by discarding all elements at the start of it which
+  /// satisfy the given predicate.
+  ///
+  /// This example uses `trimPrefix(while:)` to remove the white space at the
+  /// beginning of the string:
+  ///
+  ///     let myString = "  hello, world  "
+  ///     myString.trimPrefix(while: \.isWhitespace)
+  ///     print(myString) // "hello, world  "
+  ///
+  /// - Parameter predicate: A closure which determines if the element should be
+  ///   removed from the string.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of this collection.
+  ///
+  @inlinable
+  @_disfavoredOverload
+  public mutating func trimPrefix(
+    while predicate: (Element) throws -> Bool
+  ) rethrows {
+    let end = try endOfPrefix(while: predicate)
+    removeSubrange(startIndex..<end)
+  }
+}
+
+extension Collection where Self == Self.SubSequence {
+  /// Mutates a `Collection` by discarding all elements at the start of it which
+  /// satisfy the given predicate.
+  ///
+  /// This example uses `trimPrefix(while:)` to remove the white space at the
+  /// beginning of the string:
+  ///
+  ///     let myString = "  hello, world  "
+  ///     myString.trimPrefix(while: \.isWhitespace)
+  ///     print(myString) // "hello, world  "
+  ///
+  /// - Parameters predicate: A closure which determines if the element should
+  ///   be removed from the string.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of this collection.
+  ///
+  @inlinable
+  public mutating func trimPrefix(
+    while predicate: (Element) throws -> Bool
+  ) rethrows {
+    self = try trimmingPrefix(while: predicate)
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// trimming(while:) / trimmingSuffix(while:)
+//===----------------------------------------------------------------------===//
+
+extension BidirectionalCollection {
+  /// Returns a `SubSequence` formed by discarding all elements at the start and
+  /// end of the collection which satisfy the given predicate.
+  ///
+  /// This example uses `trimming(while:)` to get a substring without the white
+  /// space at the beginning and end of the string:
+  ///
+  ///     let myString = "  hello, world  "
+  ///     print(myString.trimming(while: \.isWhitespace)) // "hello, world"
+  ///
+  /// - Parameter predicate: A closure which determines if the element should be
+  ///   omitted from the resulting slice.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of this collection.
+  ///
+  @inlinable
+  public func trimming(
+    while predicate: (Element) throws -> Bool
+  ) rethrows -> SubSequence {
+    try trimmingPrefix(while: predicate).trimmingSuffix(while: predicate)
+  }
+  
+  /// Returns a `SubSequence` formed by discarding all elements at the end of
+  /// the collection which satisfy the given predicate.
+  ///
+  /// This example uses `trimmingSuffix(while:)` to get a substring without the
+  /// white space at the end of the string:
+  ///
+  ///     let myString = "  hello, world  "
+  ///     print(myString.trimmingSuffix(while: \.isWhitespace)) // "  hello, world"
+  ///
+  /// - Parameter predicate: A closure which determines if the element should be
+  ///   omitted from the resulting slice.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of this collection.
+  ///
+  @inlinable
+  public func trimmingSuffix(
+    while predicate: (Element) throws -> Bool
+  ) rethrows -> SubSequence {
+    let end = try startOfSuffix(while: predicate)
+    return self[..<end]
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// trim(while:) / trimSuffix(while:)
+//===----------------------------------------------------------------------===//
+
+extension BidirectionalCollection where Self: RangeReplaceableCollection {
+  /// Mutates a `BidirectionalCollection` by discarding all elements at the
+  /// start and at the end of it which satisfy the given predicate.
+  ///
+  /// This example uses `trim(while:)` to remove the white space at the
+  /// beginning of the string:
+  ///
+  ///     let myString = "  hello, world  "
+  ///     myString.trim(while: \.isWhitespace)
+  ///     print(myString) // "hello, world"
+  ///
+  /// - Parameter predicate: A closure which determines if the element should be
+  ///   removed from the string.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of this collection.
+  ///
+  @inlinable
+  @_disfavoredOverload
+  public mutating func trim(
+    while predicate: (Element) throws -> Bool
+  ) rethrows {
+    try trimSuffix(while: predicate)
+    try trimPrefix(while: predicate)
+  }
+  
+  /// Mutates a `BidirectionalCollection` by discarding all elements at the end
+  /// of it which satisfy the given predicate.
+  ///
+  /// This example uses `trimSuffix(while:)` to remove the white space at the
+  /// beginning of the string:
+  ///
+  ///     let myString = "  hello, world  "
+  ///     myString.trimSuffix(while: \.isWhitespace)
+  ///     print(myString) // "  hello, world"
+  ///
+  /// - Parameter predicate: A closure which determines if the element should be
+  ///   removed from the string.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of this collection.
+  ///
+  @inlinable
+  @_disfavoredOverload
+  public mutating func trimSuffix(
+    while predicate: (Element) throws -> Bool
+  ) rethrows {
+    let start = try startOfSuffix(while: predicate)
+    removeSubrange(start..<endIndex)
+  }
+}
+
+extension BidirectionalCollection where Self == Self.SubSequence {
+  /// Mutates a `BidirectionalCollection` by discarding all elements at the
+  /// start and at the end of it which satisfy the given predicate.
+  ///
+  /// This example uses `trim(while:)` to remove the white space at the
+  /// beginning of the string:
+  ///
+  ///     let myString = "  hello, world  "
+  ///     myString.trim(while: \.isWhitespace)
+  ///     print(myString) // "hello, world"
+  ///
+  /// - Parameter predicate: A closure which determines if the element should be
+  ///   removed from the string.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of this collection.
+  ///
+  @inlinable
+  public mutating func trim(
+    while predicate: (Element) throws -> Bool
+  ) rethrows {
+    self = try trimming(while: predicate)
+  }
+
+  /// Mutates a `BidirectionalCollection` by discarding all elements at the end
+  /// of it which satisfy the given predicate.
+  ///
+  /// This example uses `trimSuffix(while:)` to remove the white space at the
+  /// beginning of the string:
+  ///
+  ///     let myString = "  hello, world  "
+  ///     myString.trimSuffix(while: \.isWhitespace)
+  ///     print(myString) // "  hello, world"
+  ///
+  /// - Parameter predicate: A closure which determines if the element should be
+  ///   removed from the string.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of this collection.
+  ///
+  @inlinable
+  public mutating func trimSuffix(
+    while predicate: (Element) throws -> Bool
+  ) rethrows {
+    self = try trimmingSuffix(while: predicate)
+  }
+}

+ 145 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Unique.swift

@@ -0,0 +1,145 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+/// A sequence wrapper that leaves out duplicate elements of a base sequence.
+public struct UniquedSequence<Base: Sequence, Subject: Hashable> {
+  /// The base collection.
+  @usableFromInline
+  internal let base: Base
+  
+  /// The projection function.
+  @usableFromInline
+  internal let projection: (Base.Element) -> Subject
+  
+  @usableFromInline
+  internal init(base: Base, projection: @escaping (Base.Element) -> Subject) {
+    self.base = base
+    self.projection = projection
+  }
+}
+
+extension UniquedSequence: Sequence {
+  /// The iterator for a `UniquedSequence` instance.
+  public struct Iterator: IteratorProtocol {
+    @usableFromInline
+    internal var base: Base.Iterator
+    
+    @usableFromInline
+    internal let projection: (Base.Element) -> Subject
+    
+    @usableFromInline
+    internal var seen: Set<Subject> = []
+    
+    @usableFromInline
+    internal init(
+      base: Base.Iterator,
+      projection: @escaping (Base.Element) -> Subject
+    ) {
+      self.base = base
+      self.projection = projection
+    }
+    
+    @inlinable
+    public mutating func next() -> Base.Element? {
+      while let element = base.next() {
+        if seen.insert(projection(element)).inserted {
+          return element
+        }
+      }
+      return nil
+    }
+  }
+  
+  @inlinable
+  public func makeIterator() -> Iterator {
+    Iterator(base: base.makeIterator(), projection: projection)
+  }
+}
+
+extension UniquedSequence: LazySequenceProtocol
+  where Base: LazySequenceProtocol {}
+
+//===----------------------------------------------------------------------===//
+// uniqued()
+//===----------------------------------------------------------------------===//
+
+extension Sequence where Element: Hashable {
+  /// Returns a sequence with only the unique elements of this sequence, in the
+  /// order of the first occurrence of each unique element.
+  ///
+  ///     let animals = ["dog", "pig", "cat", "ox", "dog", "cat"]
+  ///     let uniqued = animals.uniqued()
+  ///     print(Array(uniqued))
+  ///     // Prints '["dog", "pig", "cat", "ox"]'
+  ///
+  /// - Returns: A sequence with only the unique elements of this sequence.
+  ///  .
+  /// - Complexity: O(1).
+  @inlinable
+  public func uniqued() -> UniquedSequence<Self, Element> {
+    UniquedSequence(base: self, projection: { $0 })
+  }
+}
+
+extension Sequence {
+  /// Returns an array with the unique elements of this sequence (as determined
+  /// by the given projection), in the order of the first occurrence of each
+  /// unique element.
+  ///
+  /// This example finds the elements of the `animals` array with unique
+  /// first characters:
+  ///
+  ///     let animals = ["dog", "pig", "cat", "ox", "cow", "owl"]
+  ///     let uniqued = animals.uniqued(on: { $0.first })
+  ///     print(uniqued)
+  ///     // Prints '["dog", "pig", "cat", "ox"]'
+  ///
+  /// - Parameter projection: A closure that transforms an element into the
+  ///   value to use for uniqueness. If `projection` returns the same value for
+  ///   two different elements, the second element will be excluded from the
+  ///   resulting array.
+  ///
+  /// - Returns: An array with only the unique elements of this sequence, as
+  ///   determined by the result of `projection` for each element.
+  ///
+  /// - Complexity: O(*n*), where *n* is the length of the sequence.
+  @inlinable
+  public func uniqued<Subject: Hashable>(
+    on projection: (Element) throws -> Subject
+  ) rethrows -> [Element] {
+    var seen: Set<Subject> = []
+    var result: [Element] = []
+    for element in self {
+      if seen.insert(try projection(element)).inserted {
+        result.append(element)
+      }
+    }
+    return result
+  }
+}
+
+//===----------------------------------------------------------------------===//
+// lazy.uniqued()
+//===----------------------------------------------------------------------===//
+
+extension LazySequenceProtocol {
+  /// Returns a lazy sequence with the unique elements of this sequence (as
+  /// determined by the given projection), in the order of the first occurrence
+  /// of each unique element.
+  ///
+  /// - Complexity: O(1).
+  @inlinable
+  public func uniqued<Subject: Hashable>(
+    on projection: @escaping (Element) -> Subject
+  ) -> UniquedSequence<Self, Subject> {
+    UniquedSequence(base: self, projection: projection)
+  }
+}

+ 360 - 0
Pods/SwiftAlgorithms/Sources/Algorithms/Windows.swift

@@ -0,0 +1,360 @@
+//===----------------------------------------------------------------------===//
+//
+// This source file is part of the Swift Algorithms open source project
+//
+// Copyright (c) 2020 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+// windows(ofCount:)
+//===----------------------------------------------------------------------===//
+
+extension Collection {
+  /// Returns a collection of all the overlapping slices of a given size.
+  ///
+  /// Use this method to iterate over overlapping subsequences of this
+  /// collection. This example prints every five character substring of `str`:
+  ///
+  ///     let str = "Hello, world!"
+  ///     for substring in str.windows(ofCount: 5) {
+  ///         print(substring)
+  ///     }
+  ///     // "Hello"
+  ///     // "ello,"
+  ///     // "llo, "
+  ///     // "lo, W"
+  ///     // ...
+  ///     // "orld!"
+  ///
+  /// - Parameter count: The number of elements in each window subsequence.
+  /// - Returns: A collection of subsequences of this collection, each with
+  ///   length `count`. If this collection is shorter than `count`, the
+  ///   resulting collection is empty.
+  ///
+  /// - Complexity: O(1) if the collection conforms to
+  ///   `RandomAccessCollection`, otherwise O(*k*) where `k` is `count`.
+  ///   Access to successive windows is O(1).
+  @inlinable
+  public func windows(ofCount count: Int) -> WindowsOfCountCollection<Self> {
+    WindowsOfCountCollection(base: self, windowSize: count)
+  }
+}
+
+/// A collection wrapper that presents a sliding window over the elements of
+/// a collection.
+public struct WindowsOfCountCollection<Base: Collection> {
+  @usableFromInline
+  internal let base: Base
+  
+  @usableFromInline
+  internal let windowSize: Int
+  
+  @usableFromInline
+  internal var endOfFirstWindow: Base.Index?
+
+  @inlinable
+  internal init(base: Base, windowSize: Int) {
+    precondition(windowSize > 0, "Windows size must be greater than zero")
+    self.base = base
+    self.windowSize = windowSize
+    self.endOfFirstWindow =
+      base.index(base.startIndex, offsetBy: windowSize, limitedBy: base.endIndex)
+  }
+}
+
+extension WindowsOfCountCollection: Collection {
+  /// A position in a `WindowsOfCountCollection` instance.
+  public struct Index: Comparable {
+    @usableFromInline
+    internal var lowerBound: Base.Index
+    
+    @usableFromInline
+    internal var upperBound: Base.Index
+    
+    @inlinable
+    internal init(lowerBound: Base.Index, upperBound: Base.Index) {
+      self.lowerBound = lowerBound
+      self.upperBound = upperBound
+    }
+    
+    @inlinable
+    public static func == (lhs: Index, rhs: Index) -> Bool {
+      lhs.lowerBound == rhs.lowerBound
+    }
+    
+    @inlinable
+    public static func < (lhs: Index, rhs: Index) -> Bool {
+      lhs.lowerBound < rhs.lowerBound
+    }
+  }
+  
+  @inlinable
+  public var startIndex: Index {
+    if let upperBound = endOfFirstWindow {
+      return Index(lowerBound: base.startIndex, upperBound: upperBound)
+    } else {
+      return endIndex
+    }
+  }
+  
+  @inlinable
+  public var endIndex: Index {
+    Index(lowerBound: base.endIndex, upperBound: base.endIndex)
+  }
+  
+  @inlinable
+  public subscript(index: Index) -> Base.SubSequence {
+    precondition(
+      index.lowerBound != index.upperBound,
+      "Windows index is out of range")
+    return base[index.lowerBound..<index.upperBound]
+  }
+  
+  @inlinable
+  public func index(after index: Index) -> Index {
+    precondition(index != endIndex, "Advancing past end index")
+    guard index.upperBound < base.endIndex else { return endIndex }
+    
+    let lowerBound = windowSize == 1
+      ? index.upperBound
+      : base.index(after: index.lowerBound)
+    let upperBound = base.index(after: index.upperBound)
+    return Index(lowerBound: lowerBound, upperBound: upperBound)
+  }
+  
+  @inlinable
+  public func index(_ i: Index, offsetBy distance: Int) -> Index {
+    guard distance != 0 else { return i }
+    
+    return distance > 0
+      ? offsetForward(i, by: distance)
+      : offsetBackward(i, by: -distance)
+  }
+  
+  @inlinable
+  public func index(
+    _ i: Index,
+    offsetBy distance: Int,
+    limitedBy limit: Index
+  ) -> Index? {
+    guard distance != 0 else { return i }
+    guard limit != i else { return nil }
+    
+    if distance > 0 {
+      return limit > i
+        ? offsetForward(i, by: distance, limitedBy: limit)
+        : offsetForward(i, by: distance)
+    } else {
+      return limit < i
+        ? offsetBackward(i, by: -distance, limitedBy: limit)
+        : offsetBackward(i, by: -distance)
+    }
+  }
+  
+  @inlinable
+  internal func offsetForward(_ i: Index, by distance: Int) -> Index {
+    guard let index = offsetForward(i, by: distance, limitedBy: endIndex)
+      else { fatalError("Index is out of bounds") }
+    return index
+  }
+  
+  @inlinable
+  internal func offsetBackward(_ i: Index, by distance: Int) -> Index {
+    guard let index = offsetBackward(i, by: distance, limitedBy: startIndex)
+      else { fatalError("Index is out of bounds") }
+    return index
+  }
+  
+  @inlinable
+  internal func offsetForward(
+    _ i: Index, by distance: Int, limitedBy limit: Index
+  ) -> Index? {
+    assert(distance > 0)
+    assert(limit > i)
+    
+    // `endIndex` and the index before it both have `base.endIndex` as their
+    // upper bound, so we first advance to the base index _before_ the upper
+    // bound of the output, in order to avoid advancing past the end of `base`
+    // when advancing to `endIndex`.
+    //
+    // Advancing by 4:
+    //
+    //  input: [x|x x x x x|x x x x]        [x x|x x x x x|x x x]
+    //                     |> > >|>|   or                 |> > >|
+    // output: [x x x x x|x x x x x]        [x x x x x x x x x x]  (`endIndex`)
+    
+    if distance >= windowSize {
+      // Avoid traversing `self[i.lowerBound..<i.upperBound]` when the lower
+      // bound of the output is greater than or equal to the upper bound of the
+      // input.
+      
+      //  input: [x|x x x x|x x x x x x x]
+      //                   |> >|> > >|>|
+      // output: [x x x x x x x|x x x x|x]
+      
+      guard limit.lowerBound >= i.upperBound,
+            let lowerBound = base.index(
+              i.upperBound,
+              offsetBy: distance - windowSize,
+              limitedBy: limit.lowerBound),
+            let indexBeforeUpperBound = base.index(
+              lowerBound,
+              offsetBy: windowSize - 1,
+              limitedBy: limit.upperBound)
+      else { return nil }
+      
+      // If `indexBeforeUpperBound` equals `base.endIndex`, we're advancing to
+      // `endIndex`.
+      guard indexBeforeUpperBound != base.endIndex else { return endIndex }
+      
+      return Index(
+        lowerBound: lowerBound,
+        upperBound: base.index(after: indexBeforeUpperBound))
+    } else {
+      //  input: [x|x x x x x x|x x x x x]
+      //           |> > > >|   |> > >|>|
+      // output: [x x x x x|x x x x x x|x]
+      
+      guard let indexBeforeUpperBound = base.index(
+              i.upperBound,
+              offsetBy: distance - 1,
+              limitedBy: limit.upperBound)
+      else { return nil }
+      
+      // If `indexBeforeUpperBound` equals the limit, the upper bound itself
+      // exceeds it.
+      guard indexBeforeUpperBound != limit.upperBound || limit == endIndex
+        else { return nil }
+      
+      // If `indexBeforeUpperBound` equals `base.endIndex`, we're advancing to
+      // `endIndex`.
+      guard indexBeforeUpperBound != base.endIndex else { return endIndex }
+      
+      return Index(
+        lowerBound: base.index(i.lowerBound, offsetBy: distance),
+        upperBound: base.index(after: indexBeforeUpperBound))
+    }
+  }
+  
+  @inlinable
+  internal func offsetBackward(
+      _ i: Index, by distance: Int, limitedBy limit: Index
+    ) -> Index? {
+    assert(distance > 0)
+    assert(limit < i)
+    
+    if i == endIndex {
+      // Advance `base.endIndex` by `distance - 1`, because the index before
+      // `endIndex` also has `base.endIndex` as its upper bound.
+      //
+      // Advancing by 4:
+      //
+      //  input: [x x x x x x x x x x]  (`endIndex`)
+      //             |< < < < <|< < <|
+      // output: [x x|x x x x x|x x x]
+      
+      guard let upperBound = base.index(
+              base.endIndex,
+              offsetBy: -(distance - 1),
+              limitedBy: limit.upperBound)
+      else { return nil }
+      
+      return Index(
+        lowerBound: base.index(upperBound, offsetBy: -windowSize),
+        upperBound: upperBound)
+    } else if distance >= windowSize {
+      // Avoid traversing `self[i.lowerBound..<i.upperBound]` when the upper
+      // bound of the output is less than or equal to the lower bound of the
+      // input.
+      //
+      //  input: [x x x x x x x|x x x x|x]
+      //           |< < < <|< <|
+      // output: [x|x x x x|x x x x x x x]
+      
+      guard limit.upperBound <= i.lowerBound,
+            let upperBound = base.index(
+              i.lowerBound,
+              offsetBy: -(distance - windowSize),
+              limitedBy: limit.upperBound)
+      else { return nil }
+      
+      return Index(
+        lowerBound: base.index(upperBound, offsetBy: -windowSize),
+        upperBound: upperBound)
+    } else {
+      //  input: [x x x x x|x x x x x x|x]
+      //           |< < < <|   |< < < <|
+      // output: [x|x x x x x x|x x x x x]
+      
+      guard let lowerBound = base.index(
+              i.lowerBound,
+              offsetBy: -distance,
+              limitedBy: limit.lowerBound)
+      else { return nil }
+      
+      return Index(
+        lowerBound: lowerBound,
+        upperBound: base.index(i.lowerBound, offsetBy: -distance))
+    }
+  }
+  
+  @inlinable
+  public func distance(from start: Index, to end: Index) -> Int {
+    guard start <= end else { return -distance(from: end, to: start) }
+    guard start != end else { return 0 }
+    guard end != endIndex else {
+      // We add 1 here because the index before `endIndex` also has
+      // `base.endIndex` as its upper bound.
+      return base[start.upperBound...].count + 1
+    }
+
+    if start.upperBound <= end.lowerBound {
+      // The distance between `start.lowerBound` and `start.upperBound` is
+      // already known.
+      //
+      // start: [x|x x x x|x x x x x x x]
+      //          |- - - -|> >|
+      //   end: [x x x x x x x|x x x x|x]
+      
+      return windowSize + base[start.upperBound..<end.lowerBound].count
+    } else {
+      // start: [x|x x x x x x|x x x x x]
+      //          |> > > >|
+      //   end: [x x x x x|x x x x x x|x]
+      
+      return base[start.lowerBound..<end.lowerBound].count
+    }
+  }
+}
+
+extension WindowsOfCountCollection: BidirectionalCollection
+  where Base: BidirectionalCollection
+{
+  @inlinable
+  public func index(before index: Index) -> Index {
+    precondition(index != startIndex, "Incrementing past start index")
+    if index == endIndex {
+      return Index(
+        lowerBound: base.index(index.lowerBound, offsetBy: -windowSize),
+        upperBound: index.upperBound
+      )
+    } else {
+      return Index(
+        lowerBound: base.index(before: index.lowerBound),
+        upperBound: base.index(before: index.upperBound)
+      )
+    }
+  }
+}
+
+extension WindowsOfCountCollection: RandomAccessCollection
+  where Base: RandomAccessCollection {}
+
+extension WindowsOfCountCollection: LazySequenceProtocol, LazyCollectionProtocol
+  where Base: LazySequenceProtocol {}
+
+extension WindowsOfCountCollection.Index: Hashable where Base.Index: Hashable {}

+ 26 - 0
Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms-Info.plist

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+  <key>CFBundleDevelopmentRegion</key>
+  <string>en</string>
+  <key>CFBundleExecutable</key>
+  <string>${EXECUTABLE_NAME}</string>
+  <key>CFBundleIdentifier</key>
+  <string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
+  <key>CFBundleInfoDictionaryVersion</key>
+  <string>6.0</string>
+  <key>CFBundleName</key>
+  <string>${PRODUCT_NAME}</string>
+  <key>CFBundlePackageType</key>
+  <string>FMWK</string>
+  <key>CFBundleShortVersionString</key>
+  <string>1.0.0</string>
+  <key>CFBundleSignature</key>
+  <string>????</string>
+  <key>CFBundleVersion</key>
+  <string>${CURRENT_PROJECT_VERSION}</string>
+  <key>NSPrincipalClass</key>
+  <string></string>
+</dict>
+</plist>

+ 5 - 0
Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms-dummy.m

@@ -0,0 +1,5 @@
+#import <Foundation/Foundation.h>
+@interface PodsDummy_SwiftAlgorithms : NSObject
+@end
+@implementation PodsDummy_SwiftAlgorithms
+@end

+ 12 - 0
Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms-prefix.pch

@@ -0,0 +1,12 @@
+#ifdef __OBJC__
+#import <UIKit/UIKit.h>
+#else
+#ifndef FOUNDATION_EXPORT
+#if defined(__cplusplus)
+#define FOUNDATION_EXPORT extern "C"
+#else
+#define FOUNDATION_EXPORT extern
+#endif
+#endif
+#endif
+

+ 16 - 0
Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms-umbrella.h

@@ -0,0 +1,16 @@
+#ifdef __OBJC__
+#import <UIKit/UIKit.h>
+#else
+#ifndef FOUNDATION_EXPORT
+#if defined(__cplusplus)
+#define FOUNDATION_EXPORT extern "C"
+#else
+#define FOUNDATION_EXPORT extern
+#endif
+#endif
+#endif
+
+
+FOUNDATION_EXPORT double AlgorithmsVersionNumber;
+FOUNDATION_EXPORT const unsigned char AlgorithmsVersionString[];
+

+ 13 - 0
Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms.debug.xcconfig

@@ -0,0 +1,13 @@
+CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO
+CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/SwiftAlgorithms
+GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
+LIBRARY_SEARCH_PATHS = $(inherited) "${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
+OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS
+PODS_BUILD_DIR = ${BUILD_DIR}
+PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
+PODS_ROOT = ${SRCROOT}
+PODS_TARGET_SRCROOT = ${PODS_ROOT}/SwiftAlgorithms
+PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates
+PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier}
+SKIP_INSTALL = YES
+USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES

+ 6 - 0
Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms.modulemap

@@ -0,0 +1,6 @@
+framework module Algorithms {
+  umbrella header "SwiftAlgorithms-umbrella.h"
+
+  export *
+  module * { export * }
+}

+ 13 - 0
Pods/Target Support Files/SwiftAlgorithms/SwiftAlgorithms.release.xcconfig

@@ -0,0 +1,13 @@
+CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO
+CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/SwiftAlgorithms
+GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
+LIBRARY_SEARCH_PATHS = $(inherited) "${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
+OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS
+PODS_BUILD_DIR = ${BUILD_DIR}
+PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
+PODS_ROOT = ${SRCROOT}
+PODS_TARGET_SRCROOT = ${PODS_ROOT}/SwiftAlgorithms
+PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates
+PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier}
+SKIP_INSTALL = YES
+USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES