Skip to content

Commit

Permalink
Rename WindowsCollection to WindowsOfCountCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Vermeulen committed Sep 8, 2021
1 parent 9650a85 commit b14b7f4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ This project follows semantic versioning.
StrideSequence -> StridingSequence
StrideCollection -> StridingCollection
Uniqued -> UniquedSequence
Windows -> WindowsCollection
Windows -> WindowsOfCountCollection
```
- Types that can only be produced from a lazy sequence chain now unconditionally
conform to `LazySequenceProtocol` and wrap the base sequence instead of the
Expand Down
4 changes: 2 additions & 2 deletions Guides/Windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The `windows(ofCount:)` method is added as an extension `Collection` method:

```swift
extension Collection {
public func windows(ofCount count: Int) -> WindowsCollection<Self>
public func windows(ofCount count: Int) -> WindowsOfCountCollection<Self>
}
```

Expand All @@ -34,7 +34,7 @@ collection is empty.
[1, 2, 3].windows(ofCount: 5).isEmpty // true
```

The resulting `WindowsCollection` type is a collection, with conditional
The resulting `WindowsOfCountCollection` type is a collection, with conditional
conformance to the `BidirectionalCollection`, `RandomAccessCollection`, and
`LazySequenceProtocol` protocols when the base collection conforms.

Expand Down
18 changes: 9 additions & 9 deletions Sources/Algorithms/Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ extension Collection {
/// `RandomAccessCollection`, otherwise O(*k*) where `k` is `count`.
/// Access to successive windows is O(1).
@inlinable
public func windows(ofCount count: Int) -> WindowsCollection<Self> {
WindowsCollection(base: self, windowSize: count)
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 WindowsCollection<Base: Collection> {
public struct WindowsOfCountCollection<Base: Collection> {
@usableFromInline
internal let base: Base

Expand All @@ -66,8 +66,8 @@ public struct WindowsCollection<Base: Collection> {
}
}

extension WindowsCollection: Collection {
/// A position in a `WindowsCollection` instance.
extension WindowsOfCountCollection: Collection {
/// A position in a `WindowsOfCountCollection` instance.
public struct Index: Comparable {
@usableFromInline
internal var lowerBound: Base.Index
Expand Down Expand Up @@ -331,7 +331,7 @@ extension WindowsCollection: Collection {
}
}

extension WindowsCollection: BidirectionalCollection
extension WindowsOfCountCollection: BidirectionalCollection
where Base: BidirectionalCollection
{
@inlinable
Expand All @@ -351,10 +351,10 @@ extension WindowsCollection: BidirectionalCollection
}
}

extension WindowsCollection: RandomAccessCollection
extension WindowsOfCountCollection: RandomAccessCollection
where Base: RandomAccessCollection {}

extension WindowsCollection: LazySequenceProtocol, LazyCollectionProtocol
extension WindowsOfCountCollection: LazySequenceProtocol, LazyCollectionProtocol
where Base: LazySequenceProtocol {}

extension WindowsCollection.Index: Hashable where Base.Index: Hashable {}
extension WindowsOfCountCollection.Index: Hashable where Base.Index: Hashable {}
2 changes: 1 addition & 1 deletion Tests/SwiftAlgorithmsTests/WindowsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final class WindowsTests: XCTestCase {
}

func testWindowsIndexTraversals() {
let validator = IndexValidator<WindowsCollection<String>>(
let validator = IndexValidator<WindowsOfCountCollection<String>>(
indicesIncludingEnd: { windows in
let endIndex = windows.base.endIndex
let indices = windows.base.indices + [endIndex]
Expand Down

0 comments on commit b14b7f4

Please sign in to comment.