mirror of
https://github.com/apple/swift-collections
synced 2026-11-27 04:54:21 +00:00
Add cursor tests and set iterator.
Major Changes: - Implement Sequence for SortedSet Minor Changes: - Fix bug within _Node.UnsafeHandle.pointerToChild(atSlot:) - Cleanup cursor implementation and fix bugs. - Fix various bugs in _BTree.FixedSizeArray
This commit is contained in:
6 files changed
+178
-59
No files matched your search
@@ -0,0 +1,39 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// TODO: add custom forEach?
|
||||
// TODO: benchmark
|
||||
|
||||
extension SortedSet: Sequence {
|
||||
/// An iterator over the elements of the sorted set
|
||||
public struct Iterator: IteratorProtocol {
|
||||
@usableFromInline
|
||||
internal var _iterator: _Tree.Iterator
|
||||
|
||||
@inlinable
|
||||
internal init(_base: SortedSet) {
|
||||
self._iterator = _base._root.makeIterator()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public mutating func next() -> Element? {
|
||||
return self._iterator.next()?.key
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an iterator over the elements of the sorted dictionary.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@inlinable
|
||||
public __consuming func makeIterator() -> Iterator {
|
||||
return Iterator(_base: self)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user