Skip to content

Commit aba0791

Browse files
authored
Merge pull request #119 from lorentey/remove-heap-views
[Heap] Remove Heap's `ascending` and `descending` views
2 parents fc876e1 + f41f2ca commit aba0791

File tree

3 files changed

+6
-91
lines changed

3 files changed

+6
-91
lines changed

Documentation/Heap.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,7 @@ We also have non-optional flavors that assume the heap isn't empty, `removeMin()
104104

105105
### Iteration
106106

107-
`Heap` itself doesn't conform to `Sequence` because of the potential confusion around which direction it should iterate (largest-to-smallest? smallest-to-largest?). Instead, we expose two iterators that conform to `Sequence`:
108-
109-
```swift
110-
for val in heap.ascending {
111-
...
112-
}
113-
114-
for val in heap.descending {
115-
...
116-
}
117-
```
107+
`Heap` itself doesn't conform to `Sequence` because of the potential confusion around which direction it should iterate (largest-to-smallest? smallest-to-largest?).
118108

119109
### Performance
120110

Sources/PriorityQueueModule/Heap+OrderedViews.swift

Lines changed: 0 additions & 62 deletions
This file was deleted.

Tests/PriorityQueueTests/HeapTests.swift

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ final class HeapTests: XCTestCase {
9090
heap.insert(contentsOf: sequence(first: 1, next: addTwo(_:)).prefix(20))
9191
XCTAssertEqual(heap.count, 40)
9292

93-
for (idx, i) in heap.ascending.enumerated() {
94-
XCTAssertEqual(idx, i)
93+
var i = 0
94+
while let min = heap.popMin() {
95+
XCTAssertEqual(min, i)
96+
i += 1
9597
}
98+
XCTAssertEqual(i, 40)
9699
}
97100

98101
func test_min() {
@@ -403,21 +406,5 @@ final class HeapTests: XCTestCase {
403406
XCTAssertEqual(heap.popMax(), 3)
404407
XCTAssertEqual(heap.popMax(), 1)
405408
}
406-
407-
func test_sequenceConformance() {
408-
let heap = Heap<Int>((0...50).shuffled())
409-
410-
var increment = 0
411-
for val in heap.ascending {
412-
XCTAssertEqual(increment, val)
413-
increment += 1
414-
}
415-
416-
increment = 50
417-
for val in heap.descending {
418-
XCTAssertEqual(increment, val)
419-
increment -= 1
420-
}
421-
}
422409
}
423410
#endif

0 commit comments

Comments
 (0)