A map that returns the value associated with the closest key.
When looking up a key, returns the value for the key in the map that is closest to the query. For numeric keys, distance is |query - key|.
Tie-breaking: When two keys are equidistant, use :< to prefer the smaller key, or :> to prefer the larger key.
A map that returns the value associated with the closest key. When looking up a key, returns the value for the key in the map that is closest to the query. For numeric keys, distance is |query - key|. Tie-breaking: When two keys are equidistant, use :< to prefer the smaller key, or :> to prefer the larger key.
A set that returns the closest element to a query.
When looking up a value, returns the element in the set that is closest to the query. For numeric keys, distance is |query - element|.
Tie-breaking: When two elements are equidistant, use :< to prefer the smaller element, or :> to prefer the larger element.
A set that returns the closest element to a query. When looking up a value, returns the element in the set that is closest to the query. For numeric keys, distance is |query - element|. Tie-breaking: When two elements are equidistant, use :< to prefer the smaller element, or :> to prefer the larger element.
Protocol extensions for interoperability with standard Clojure collections.
Extends ordered-collections protocols to:
This allows protocol functions like union, intersection, nearest, etc. to work with standard Clojure sorted collections.
Protocol extensions for interoperability with standard Clojure collections. Extends ordered-collections protocols to: - PersistentHashSet - PersistentTreeSet - PersistentTreeMap This allows protocol functions like union, intersection, nearest, etc. to work with standard Clojure sorted collections.
No vars found in this namespace.
No vars found in this namespace.
No vars found in this namespace.
Persistent sorted multiset (bag) backed by a weight-balanced tree.
Internally an ordered map from elements to counts (longs). The public API expands each entry into repeated elements: an element with count 3 appears three times in seq, reduce, and nth.
Persistent sorted multiset (bag) backed by a weight-balanced tree. Internally an ordered map from elements to counts (longs). The public API expands each entry into repeated elements: an element with count 3 appears three times in seq, reduce, and nth.
No vars found in this namespace.
Persistent priority queue backed by a weight-balanced tree.
Internally an ordered map from priorities to vectors of values. Duplicate priorities are stable in insertion order. The public API exposes [priority value] pairs; the vector grouping is hidden.
Persistent priority queue backed by a weight-balanced tree. Internally an ordered map from priorities to vectors of values. Duplicate priorities are stable in insertion order. The public API exposes [priority value] pairs; the vector grouping is hidden.
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).
Persistent rope-like indexed sequence backed by an implicit-index weight-balanced tree.
Persistent rope-like indexed sequence backed by an implicit-index weight-balanced tree.
A segment tree for efficient range aggregate queries.
Supports O(log n) point updates and O(log n) range queries for any associative operation (sum, min, max, gcd, etc.).
CONCEPT: Each node stores an aggregate of its entire subtree. For sum:
┌─────────────┐
│ key: 3 │
│ val: 40 │
│ agg: 150 ◄──────── sum of entire tree
└──────┬──────┘
┌───────────┴───────────┐
┌──────┴──────┐ ┌──────┴──────┐
│ key: 1 │ │ key: 4 │
│ val: 20 │ │ val: 50 │
│ agg: 30 ◄─────── │ agg: 80 ◄───────
└──────┬──────┘ │ └──────┬──────┘ │
│ │ │ │
┌──────┴──────┐ │ ┌──────┴──────┐ │
│ key: 0 │ │ │ key: 5 │ │
│ val: 10 │ │ │ val: 30 │ │
│ agg: 10 │ │ │ agg: 30 │ │
└─────────────┘ │ └─────────────┘ │
│ │
10 + 20 = 30 50 + 30 = 80
RANGE QUERY: query(1, 4) = sum of indices 1,2,3,4 Uses aggregates to avoid visiting every node - O(log n).
EXAMPLE: (def st (segment-tree + 0 {0 10, 1 20, 2 30, 3 40, 4 50})) (query st 0 4) ; => 150 (sum of all) (query st 1 3) ; => 90 (20 + 30 + 40) (update st 2 100) ; => new tree with index 2 = 100 (query st 1 3) ; => 160 (20 + 100 + 40)
A segment tree for efficient range aggregate queries.
Supports O(log n) point updates and O(log n) range queries for any
associative operation (sum, min, max, gcd, etc.).
CONCEPT:
Each node stores an aggregate of its entire subtree. For sum:
┌─────────────┐
│ key: 3 │
│ val: 40 │
│ agg: 150 ◄──────── sum of entire tree
└──────┬──────┘
┌───────────┴───────────┐
┌──────┴──────┐ ┌──────┴──────┐
│ key: 1 │ │ key: 4 │
│ val: 20 │ │ val: 50 │
│ agg: 30 ◄─────── │ agg: 80 ◄───────
└──────┬──────┘ │ └──────┬──────┘ │
│ │ │ │
┌──────┴──────┐ │ ┌──────┴──────┐ │
│ key: 0 │ │ │ key: 5 │ │
│ val: 10 │ │ │ val: 30 │ │
│ agg: 10 │ │ │ agg: 30 │ │
└─────────────┘ │ └─────────────┘ │
│ │
10 + 20 = 30 50 + 30 = 80
RANGE QUERY: query(1, 4) = sum of indices 1,2,3,4
Uses aggregates to avoid visiting every node - O(log n).
EXAMPLE:
(def st (segment-tree + 0 {0 10, 1 20, 2 30, 3 40, 4 50}))
(query st 0 4) ; => 150 (sum of all)
(query st 1 3) ; => 90 (20 + 30 + 40)
(update st 2 100) ; => new tree with index 2 = 100
(query st 1 3) ; => 160 (20 + 100 + 40)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 |