mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-30 04:48:43 +00:00
Prepare for Swift Algorithms 1.0 (#167)
* Rename types to include a Sequence or Collection suffix, and clean up some guides * Various refactors * Replace `validateIndexTraversals` test method with `IndexValidator` type * Add LazySequenceProtocol to StridingSequence, StridingCollection * Update the Numerics dependency to 1.0 * Set `IndexedCollection.Indices` to `Base.Indices` * Remove deprecations * Update the changelog/README for the 1.0.0 release * Fix compiler error on Linux * Rename `WindowsCollection` to `WindowsOfCountCollection`
This commit is contained in:
1 parent
e195266e1f
commit
c5ea9e3e36
61 files changed
+1608
-1273
No files matched your search
@@ -12,7 +12,9 @@
|
||||
/// A collection consisting of all the elements contained in a collection of
|
||||
/// collections.
|
||||
@usableFromInline
|
||||
internal struct FlattenCollection<Base: Collection> where Base.Element: Collection {
|
||||
internal struct FlattenCollection<Base: Collection>
|
||||
where Base.Element: Collection
|
||||
{
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
|
||||
@@ -97,7 +99,9 @@ extension FlattenCollection: Collection {
|
||||
guard let startInner = start.inner
|
||||
else { return 0 }
|
||||
guard start.outer != end.outer
|
||||
else { return base[start.outer].distance(from: startInner, to: end.inner!) }
|
||||
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()
|
||||
@@ -199,7 +203,10 @@ extension FlattenCollection: Collection {
|
||||
|
||||
if let limitInner = limit.inner {
|
||||
let element = base[outer]
|
||||
return element.index(element.startIndex, offsetBy: remainder, limitedBy: limitInner)
|
||||
return element.index(
|
||||
element.startIndex,
|
||||
offsetBy: remainder,
|
||||
limitedBy: limitInner)
|
||||
.map { inner in Index(outer: outer, inner: inner) }
|
||||
} else {
|
||||
return nil
|
||||
@@ -287,10 +294,8 @@ extension FlattenCollection: BidirectionalCollection
|
||||
}
|
||||
}
|
||||
|
||||
extension FlattenCollection: LazySequenceProtocol
|
||||
extension FlattenCollection: LazySequenceProtocol, LazyCollectionProtocol
|
||||
where Base: LazySequenceProtocol, Base.Element: LazySequenceProtocol {}
|
||||
extension FlattenCollection: LazyCollectionProtocol
|
||||
where Base: LazyCollectionProtocol, Base.Element: LazyCollectionProtocol {}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// joined()
|
||||
|
||||
Reference in new issue
Block a user