mirror of
https://github.com/apple/swift-collections
synced 2026-11-26 04:47:48 +00:00
[Heap] Remove Heap's ascending and descending views
These two do *very* non-trivial processing, so they don't at all work like views in the Standard Library. They also don't carry their weight -- they are simply lightweight wrappers around `popMin` and `popMax`, respectively. Let's get rid of them before we etch them in stone as public API.
This commit is contained in:
1 parent
52d426a116
commit
30e6eb1116
2 files changed
+5
-80
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