← All lints

sorted_range_method

L0515Idiomswarn

Removed bound-query method on SortedBag or SortedSet

first_ge/first_gt/last_le/last_lt/count_range on SortedBag/SortedSet: use .range(r)

Flagged
var s = SortedBag<Int>()
print(s.first_ge(3) ?? -1, s.last_lt(5) ?? -1, s.count_range(1, 5))
Write instead
var s = SortedBag<Int>()
print(s.range(3..).first ?? -1, s.range(..5).last ?? -1, s.range(1..5).len)

Why

SortedBag.range(r) and SortedSet.range(r) return an O(1)O(1) view whose .first, .last, and .len cost O(log⁡n)O(\log n) and whose iteration costs O(log⁡n+k)O(\log n + k). cpl fix rewrites first_ge/first_gt/last_le/last_lt/count_range to .range(...) calls.

The practice it serves

A hand-written pattern the language or the standard library already says in one step. Family: S.seq: ordering and ranks.

Not flagged

A near miss: close to the pattern, but not it.

Near miss
var s = SortedBag<Int>()
s.add(3)
print(s.len)

Turn it off

For one block, wrap it in with lint(sorted_range_method: allow):. For a project, add sorted_range_method = "allow" under [lints] in cp.toml.

Generated from spec/lints/sorted_range_method, the same record the linter is built from.