Package traits already pass defines with their trait name when building. Instead of adding our own conditional defines based on the traits we can use the trait provided defines directly. I observed that various tooling behaves better with the trait provided defines.
The Range<Element> subscript covers half-open intervals. Add four
concrete overloads so callers can also write set[lo...hi], set[lo...],
set[..<hi], and set[...hi] — covering every stdlib RangeExpression
type that makes sense for a sorted set.
A single generic subscript<R: RangeExpression> would have been nicer,
but RangeExpression only exposes bounds via relative(to:), which needs
a Collection with Index == Bound. Element is Comparable but not an
index of any collection we have, so the generic path doesn't work for
arbitrary Element types. Five overloads it is.
The inclusive-upper variants (ClosedRange, PartialRangeThrough) use a
private _firstTreeIndex(after:) helper that returns the first
_BTree.Index strictly greater than a given element (or endIndex) —
the same logic as the public firstIndex(after:), but returning a
_Tree.Index directly for internal use.
Tests probe every lo/hi pair using a set of even numbers, so each
query exercises both "hits a member" and "falls between members"
cases, plus bounds that extend past each end of the set.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Range<Element> subscript covers half-open intervals, and with
partial-range support it would compose into ceiling/floor/lower (first
>= x, last <= x, last < x). The strict upper bound "first element > x"
(Java's higher(_:)) can't be expressed as a range for arbitrary
Comparable types because Comparable has no successor operation, so
expose it — together with the symmetric strict lower bound — as
first-class operations.
Both are built on _BTree.startIndex(forKey:), which already returns the
first element >= the given key:
- firstIndex(after: x) advances past that index if the element there
equals x.
- lastIndex(before: x) steps back one index, or returns nil if the
lookup landed at startIndex.
Add test_firstIndexAfter and test_lastIndexBefore, covering queries
that hit an element, queries that fall between elements, and out-of-
range queries on both ends.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The indexes passed to span(after:) and friends on UniqueArray
and RigidArray are modified before return. This adds notes
about the updated values to the method documentation, along
with a few other minor formatting changes (dropping smart
quotes, single-sentence abstracts).
This re-enables the SortedCollections for easi(er) experimentation.
The module remains source unstable — it may go away entirely or it may receive arbitrary source-breaking changes in any new swift-collections release, with no special pre-announcement.
Key Changes:
- Add tests and benchmarks for SortedSet
- Fix bug during _Node.UnsafeHandle.popFirstElement() rebalancing
- Enable _Node.UnsafeHandle.subscript(elementAt:) to work on value-less nodes.
Minor Changes:
- Optimize Codable to use _BTree.Builder and forEach
- Codable now checks for order, not strictly uniqueness
- Add smaller node size for debug builds to easily catch errors
Key Changes:
- Implement Equatable, Hashable for SubSequences
- Implement SortedDictionary initializers
- init(keysWithValues:) and init(sortedKeysAndValues:) with named and unnamed variants.
- Expand benchmark suite for SortedDictionary
- Commit _BTree.Builder
Minor Changes:
- Update documentation
- Expand test suits
- Fix bug where SubSequences did not define subscript(bounds: Range<Index>)
- _Node
- Implement `depth` property for `_Node`
- Packs both `depth`, `count`, and `capacity` within a single UInt64.
- Implement `init(leftChild:seperator:rightChild:capacity:)` for `_Node`
- Implement `concatenateWith(node:seperatedBy:)` to `_Node.UnsafeHandle`
- Remove bad invariant check on `_Node.UnsafeHandle` deletion subroutines
- _BTree
- Add invariant checks as `_BTree.checkInvariants()`
- Separate `_BTree.*capacity` into `*size` and `*capacity`
- Make _FixedSizeArray top-level
- Remove deque behavior.
Documentation:
- Update complexity documentation style from 'n' to `self.count`
Testing:
- Expand tests for SortedDictionary
- Add tests for SortedDictionary.Keys
- Add tests for _Node.join(...) routines
- Add tests for _BTree.Builder
- Restore checkBidirectionalCollection tests for _BTree
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