mirror of
https://github.com/apple/swift-collections
synced 2026-11-30 05:18:44 +00:00
Merge pull request #119 from lorentey/remove-heap-views
[Heap] Remove Heap's `ascending` and `descending` views
This commit is contained in:
3 files changed
+6
-91
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user