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:
Vihan Bhargava committed 2021-08-09 19:14:19 -07:00
1 parent 5690056991
commit 21d9bde3ec
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)
}
}