mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-26 04:27:48 +00:00
Add a few missing doc comments.
This commit is contained in:
1 parent
99152ecc68
commit
638869256a
8 files changed
+32
-33
No files matched your search
@@ -26,7 +26,7 @@ public struct Chain2<Base1: Sequence, Base2: Sequence>
|
||||
}
|
||||
|
||||
extension Chain2: Sequence {
|
||||
/// The iterator for a `Chain` sequence.
|
||||
/// The iterator for a `Chain2` sequence.
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
internal var iterator1: Base1.Iterator
|
||||
@@ -53,7 +53,7 @@ extension Chain2: Sequence {
|
||||
}
|
||||
|
||||
extension Chain2: Collection where Base1: Collection, Base2: Collection {
|
||||
/// A position in a `Chain` collection.
|
||||
/// A position in a `Chain2` collection.
|
||||
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
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// A collection wrapper that breaks a collection into chunks based on a
|
||||
/// predicate or projection.
|
||||
public struct LazyChunked<Base: Collection, Subject> {
|
||||
/// The collection that this instance provides a view onto.
|
||||
public let base: Base
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// A collection wrapper that generates combinations of a base collection.
|
||||
public struct Combinations<Base: Collection> {
|
||||
/// The collection to iterate over for combinations.
|
||||
public let base: Base
|
||||
@@ -40,6 +41,7 @@ public struct Combinations<Base: Collection> {
|
||||
}
|
||||
|
||||
extension Combinations: Sequence {
|
||||
/// The iterator for a `Combinations` instance.
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
internal let base: Base
|
||||
|
||||
@@ -55,6 +55,7 @@ extension Intersperse: Sequence {
|
||||
}
|
||||
|
||||
extension Intersperse: Collection where Base: Collection {
|
||||
/// A position in an `Intersperse` collection.
|
||||
public struct Index: Comparable {
|
||||
enum Representation: Equatable {
|
||||
case element(Base.Index)
|
||||
|
||||
@@ -32,6 +32,7 @@ public struct Permutations<Base: Collection> {
|
||||
}
|
||||
|
||||
extension Permutations: Sequence {
|
||||
/// The iterator for a `Permutations` instance.
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
internal var base: Base
|
||||
|
||||
@@ -30,14 +30,15 @@ extension Collection {
|
||||
}
|
||||
}
|
||||
|
||||
/// A collection wrapper that presents a sliding window over the elements of
|
||||
/// a collection.
|
||||
public struct SlidingWindows<Base: Collection> {
|
||||
|
||||
public let base: Base
|
||||
public let size: Int
|
||||
|
||||
private var firstUpperBound: Base.Index?
|
||||
internal var firstUpperBound: Base.Index?
|
||||
|
||||
init(base: Base, size: Int) {
|
||||
internal init(base: Base, size: Int) {
|
||||
precondition(size > 0, "SlidingWindows size must be greater than zero")
|
||||
self.base = base
|
||||
self.size = size
|
||||
@@ -46,13 +47,15 @@ public struct SlidingWindows<Base: Collection> {
|
||||
}
|
||||
|
||||
extension SlidingWindows: Collection {
|
||||
|
||||
/// A position in a `SlidingWindows` collection.
|
||||
public struct Index: Comparable {
|
||||
internal var lowerBound: Base.Index
|
||||
internal var upperBound: Base.Index
|
||||
|
||||
public static func == (lhs: Index, rhs: Index) -> Bool {
|
||||
lhs.lowerBound == rhs.lowerBound
|
||||
}
|
||||
|
||||
public static func < (lhs: Index, rhs: Index) -> Bool {
|
||||
lhs.lowerBound < rhs.lowerBound
|
||||
}
|
||||
|
||||
@@ -32,12 +32,12 @@ extension Sequence {
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper that strides over a base sequence or collection.
|
||||
public struct Stride<Base: Sequence> {
|
||||
internal let base: Base
|
||||
internal let stride: Int
|
||||
|
||||
let base: Base
|
||||
let stride: Int
|
||||
|
||||
init(base: Base, stride: Int) {
|
||||
internal init(base: Base, stride: Int) {
|
||||
precondition(stride > 0, "striding must be greater than zero")
|
||||
self.base = base
|
||||
self.stride = stride
|
||||
@@ -51,12 +51,11 @@ extension Stride {
|
||||
}
|
||||
|
||||
extension Stride: Sequence {
|
||||
|
||||
/// An iterator over a `Stride` sequence.
|
||||
public struct Iterator: IteratorProtocol {
|
||||
|
||||
var iterator: Base.Iterator
|
||||
let stride: Int
|
||||
var striding: Bool = false
|
||||
internal var iterator: Base.Iterator
|
||||
internal let stride: Int
|
||||
internal var striding: Bool = false
|
||||
|
||||
public mutating func next() -> Base.Element? {
|
||||
guard striding else {
|
||||
@@ -76,12 +75,11 @@ extension Stride: Sequence {
|
||||
}
|
||||
|
||||
extension Stride: Collection where Base: Collection {
|
||||
|
||||
/// A position in a `Stride` collection.
|
||||
public struct Index: Comparable {
|
||||
internal let base: Base.Index
|
||||
|
||||
let base: Base.Index
|
||||
|
||||
init(_ base: Base.Index) {
|
||||
internal init(_ base: Base.Index) {
|
||||
self.base = base
|
||||
}
|
||||
|
||||
@@ -192,29 +190,21 @@ extension Stride: BidirectionalCollection
|
||||
}
|
||||
}
|
||||
|
||||
extension Stride: RandomAccessCollection
|
||||
where Base: RandomAccessCollection {}
|
||||
extension Stride: RandomAccessCollection where Base: RandomAccessCollection {}
|
||||
|
||||
extension Stride: Equatable
|
||||
where Base.Element: Equatable {
|
||||
|
||||
extension Stride: Equatable where Base.Element: Equatable {
|
||||
public static func == (lhs: Stride, rhs: Stride) -> Bool {
|
||||
lhs.elementsEqual(rhs, by: ==)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Stride: Hashable
|
||||
where Base.Element: Hashable {
|
||||
|
||||
extension Stride: Hashable where Base.Element: Hashable {
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(stride)
|
||||
for element in self {
|
||||
hasher.combine(element)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Stride.Index: Hashable
|
||||
where Base.Index: Hashable {}
|
||||
extension Stride.Index: Hashable where Base.Index: Hashable {}
|
||||
@@ -10,7 +10,6 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension BidirectionalCollection {
|
||||
|
||||
/// Returns a `SubSequence` formed by discarding all elements at the start and
|
||||
/// end of the collection which satisfy the given predicate.
|
||||
///
|
||||
@@ -30,11 +29,11 @@ extension BidirectionalCollection {
|
||||
public func trimming(
|
||||
where predicate: (Element) throws -> Bool
|
||||
) rethrows -> SubSequence {
|
||||
|
||||
// Consume elements from the front.
|
||||
let sliceStart = try firstIndex { try predicate($0) == false } ?? endIndex
|
||||
// sliceEnd is the index _after_ the last index to match the predicate.
|
||||
var sliceEnd = endIndex
|
||||
|
||||
while sliceStart != sliceEnd {
|
||||
let idxBeforeSliceEnd = index(before: sliceEnd)
|
||||
guard try predicate(self[idxBeforeSliceEnd]) else {
|
||||
@@ -42,6 +41,7 @@ extension BidirectionalCollection {
|
||||
}
|
||||
sliceEnd = idxBeforeSliceEnd
|
||||
}
|
||||
|
||||
// Trimmed everything.
|
||||
return self[Range(uncheckedBounds: (sliceStart, sliceStart))]
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user