mirror of
https://github.com/apple/swift-collections
synced 2026-11-24 04:27:53 +00:00
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>