diff --git a/Sources/PriorityQueueModule/Heap+OrderedViews.swift b/Sources/PriorityQueueModule/Heap+OrderedViews.swift deleted file mode 100644 index 18b6c53f..00000000 --- a/Sources/PriorityQueueModule/Heap+OrderedViews.swift +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections 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 Heap { - /// A view of a `Heap`'s elements, as a `Sequence` from the smallest to - /// largest element. - @frozen - public struct AscendingView: Sequence, IteratorProtocol { - @usableFromInline - internal var _base: Heap - - /// Creates an ascending-element view from the given heap. - @inlinable - init(_base: Heap) { - self._base = _base - } - - @inlinable - public mutating func next() -> Element? { - return _base.popMin() - } - } - - /// A view of a `Heap`'s elements, as a `Sequence` from the largest to - /// smallest element. - @frozen - public struct DescendingView: Sequence, IteratorProtocol { - @usableFromInline - internal var _base: Heap - - /// Creates a descending-element view from the given heap. - @inlinable - init(_base: Heap) { - self._base = _base - } - - @inlinable - public mutating func next() -> Element? { - return _base.popMax() - } - } - - /// Returns an iterator that orders elements from smallest to largest - @inlinable - public var ascending: AscendingView { - return AscendingView(_base: self) - } - - /// Returns an iterator that orders elements from largest to smallest - @inlinable - public var descending: DescendingView { - return DescendingView(_base: self) - } -} diff --git a/Tests/PriorityQueueTests/HeapTests.swift b/Tests/PriorityQueueTests/HeapTests.swift index ca326858..9cf2b349 100644 --- a/Tests/PriorityQueueTests/HeapTests.swift +++ b/Tests/PriorityQueueTests/HeapTests.swift @@ -90,9 +90,12 @@ final class HeapTests: XCTestCase { heap.insert(contentsOf: sequence(first: 1, next: addTwo(_:)).prefix(20)) XCTAssertEqual(heap.count, 40) - for (idx, i) in heap.ascending.enumerated() { - XCTAssertEqual(idx, i) + var i = 0 + while let min = heap.popMin() { + XCTAssertEqual(min, i) + i += 1 } + XCTAssertEqual(i, 40) } func test_min() { @@ -403,21 +406,5 @@ final class HeapTests: XCTestCase { XCTAssertEqual(heap.popMax(), 3) XCTAssertEqual(heap.popMax(), 1) } - - func test_sequenceConformance() { - let heap = Heap((0...50).shuffled()) - - var increment = 0 - for val in heap.ascending { - XCTAssertEqual(increment, val) - increment += 1 - } - - increment = 50 - for val in heap.descending { - XCTAssertEqual(increment, val) - increment -= 1 - } - } } #endif