Design decisions

103. SortedSet.range(r) and SortedBag.range(r) replace the 5 bound-query methods (2026-11-21)

  • Decision: SortedBag<K>.range(r) and SortedSet<K>.range(r) (std.bag.SortedSet, superseding OrderedSet) return an O(1) SortedRange<K> view over any ordered range (a..b, a..=b, ..b, ..=b, a.., .., or Range<D>). .first, .last, .len, and .is_empty run in O(log n) expected time; iteration (for x in s.range(r), .rev, comprehensions, and folds like .sum()) runs in O(log n + k) expected time with zero view allocation. first_ge, first_gt, last_le, last_lt, and count_range are removed from SortedBag/SortedSet with checker diagnostics and lint L0515 (cpl fix codemod) rewriting all 5 methods to .range(...).
  • Reason: Closes the cf2062e2 dream friction where querying keys outside a subtree (heavier.range(..r.lo), heavier.range(r.hi..), heavier.range(r)) needed five separate bound methods with hand-picked comparisons. Lowering SortedRange<K> to captured range bounds over the receiver place keeps view construction O(1) and matches hand-written C++ treaps (1.12x in bench/containers/sorted_range).
  • Reverse: Re-add first_ge/first_gt/last_le/last_lt/count_range on SortedBag/SortedSet in stdlib/bag.cp, remove SortedRange handling from cpl-check/cpl-ir, and drop L0515 from cpl-lint.