A map from non-overlapping ranges to values.
Unlike IntervalMap (which allows overlapping intervals), RangeMap enforces that ranges never overlap. When inserting a new range, any overlapping portions of existing ranges are removed.
SEMANTICS (compatible with Guava's TreeRangeMap):
assoc (put): inserts range, carving out overlaps. Does NOT coalesce.assoc-coalescing (putCoalescing): inserts and coalesces adjacent
same-value ranges.RANGE SEMANTICS: Ranges are half-open intervals [lo, hi) by default:
PERFORMANCE:
A map from non-overlapping ranges to values. Unlike IntervalMap (which allows overlapping intervals), RangeMap enforces that ranges never overlap. When inserting a new range, any overlapping portions of existing ranges are removed. SEMANTICS (compatible with Guava's TreeRangeMap): - `assoc` (put): inserts range, carving out overlaps. Does NOT coalesce. - `assoc-coalescing` (putCoalescing): inserts and coalesces adjacent same-value ranges. RANGE SEMANTICS: Ranges are half-open intervals [lo, hi) by default: - [0 10] contains 0, 1, 2, ..., 9 but NOT 10 PERFORMANCE: - Point lookup: O(log n) - Insert/assoc: O(k log n) where k = number of overlapping ranges - Coalescing insert: O(k log n) - Remove: O(k log n) For typical use (k=1-3 overlaps), effectively O(log n).
(assoc-coalescing rm rng v)Insert range with coalescing. Adjacent ranges with the same value are automatically merged. Equivalent to Guava's putCoalescing.
Example: (-> (range-map) (assoc-coalescing [0 100] :a) (assoc-coalescing [100 200] :a)) ;; => single range [0 200) :a
Insert range with coalescing. Adjacent ranges with the same value
are automatically merged. Equivalent to Guava's putCoalescing.
Example:
(-> (range-map)
(assoc-coalescing [0 100] :a)
(assoc-coalescing [100 200] :a))
;; => single range [0 200) :a(gaps rm)Return a seq of [lo hi) ranges that have no mapping.
Return a seq of [lo hi) ranges that have no mapping.
(get-entry rm x)Return [range value] for the range containing point x, or nil. Equivalent to Guava's getEntry(K).
Example: (get-entry rm 50) ;; => [[0 100] :a]
Return [range value] for the range containing point x, or nil. Equivalent to Guava's getEntry(K). Example: (get-entry rm 50) ;; => [[0 100] :a]
(range-map)(range-map coll)Create a range map from a collection of [range value] pairs.
Ranges are [lo hi) (half-open, hi exclusive).
Example: (range-map {[0 10] :a [20 30] :b}) (range-map [[[0 10] :a] [[20 30] :b]])
Create a range map from a collection of [range value] pairs.
Ranges are [lo hi) (half-open, hi exclusive).
Example:
(range-map {[0 10] :a [20 30] :b})
(range-map [[[0 10] :a] [[20 30] :b]])(range-remove rm rng)Remove all mappings in the given range [lo hi). Any overlapping ranges are trimmed; ranges fully contained are removed. Equivalent to Guava's remove(Range).
Example: (range-remove rm [25 75]) ;; [0 100]:a becomes [0 25):a and [75 100):a
Remove all mappings in the given range [lo hi). Any overlapping ranges are trimmed; ranges fully contained are removed. Equivalent to Guava's remove(Range). Example: (range-remove rm [25 75]) ;; [0 100]:a becomes [0 25):a and [75 100):a
(ranges rm)Return a seq of all [range value] pairs.
Return a seq of all [range value] pairs.
(span rm)Return [lo hi] spanning all ranges, or nil if empty.
Return [lo hi] spanning all ranges, or nil if empty.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |