Utilities to work with data.avl sorted collections
Utilities to work with data.avl sorted collections
Protocol to make some fns work both on sorted maps and sorted sets. For sorted maps, will return the key of the entry. For sorted sets, the entry is the key.
Protocol to make some fns work both on sorted maps and sorted sets. For sorted maps, will return the key of the entry. For sorted sets, the entry is the key.
(-entry-key this entry)
(-full-tail-vec-fn f)
Returns a full-tail
function where items are mapped using f
when building the resulting vector.
Returns a [[full-tail]] function where items are mapped using `f` when building the resulting vector.
(-tail-vec-fn f)
Returns a tail
function where items are mapped using f
when building the resulting vector.
Returns a [[tail]] function where items are mapped using `f` when building the resulting vector.
(datafy-avl!)
Calls both datafy-avl-maps!
and datafy-avl-sets!
Calls both [[datafy-avl-maps!]] and [[datafy-avl-sets!]]
(datafy-avl-maps!)
Makes clojure.data.avl.AVLMap implement p/Datafiable. datafy on an AVLMap will return a clojure.core sorted-map.
Makes clojure.data.avl.AVLMap implement p/Datafiable. datafy on an AVLMap will return a clojure.core sorted-map.
(datafy-avl-sets!)
Makes clojure.data.avl.AVLSet implement p/Datafiable. datafy on an AVLMap will return a clojure.core sorted-set
Makes clojure.data.avl.AVLSet implement p/Datafiable. datafy on an AVLMap will return a clojure.core sorted-set
(first sc)
Returns the first element of sorted collection sc
if not empty, else nil.
Returns the first element of sorted collection `sc` if not empty, else nil.
(first-key sm)
Returns the first key of sorted map sm
, or nil if empty.
Same as (some-> (first sm) key)
Returns the first key of sorted map `sm`, or nil if empty. Same as (some-> (first sm) key)
(first-val sm)
Returns the first val of sorted map sm
, or nil if empty.
Same as (some-> (first sm) val)
Returns the first val of sorted map `sm`, or nil if empty. Same as (some-> (first sm) val)
(full-tail-sorted sc n)
(full-tail-sorted sc n end-k)
Faster (some->> (full-tail sc n) (into (avl/sorted-map))). See full-tail
Faster (some->> (full-tail sc n) (into (avl/sorted-map))). See [[full-tail]]
(index-by f coll)
(index-by cmp f coll)
Given an (optional) comparator cmp
, function f
and coll
, creates a new sorted-map whose keys
are obtained by calling f
on each coll
element and vals are the element untouched.
Given an (optional) comparator `cmp`, function `f` and `coll`, creates a new sorted-map whose keys are obtained by calling `f` on each `coll` element and vals are the element untouched.
(last sc)
Returns the last element of sorted collection sc
, or nil if sc is empty.
Returns the last element of sorted collection `sc`, or nil if sc is empty.
(last-key sc)
Returns last key of sorted map sm
, or nil if sm
is empty.
Same as (some-> (last sm) key)
Returns last key of sorted map `sm`, or nil if `sm` is empty. Same as (some-> (last sm) key)
(last-val sc)
Returns last key of sorted map sm
, or nil if sm
is empty.
Same as (some-> (last sm) val)
Returns last key of sorted map `sm`, or nil if `sm` is empty. Same as (some-> (last sm) val)
(nearest-key sm test k)
Same as (some-> (avl/nearest sm test k) key).
Same as (some-> (avl/nearest sm test k) key).
(nearest-rank sc test k)
Returns the rank of the nearest key. Same as (rank-of sc (nearest-key sc test k))
Returns the rank of the nearest key. Same as (rank-of sc (nearest-key sc test k))
(nearest-val sm test k)
Same as (some-> (avl/nearest sm test k) val).
Same as (some-> (avl/nearest sm test k) val).
(nth sc idx)
Like clojure.core/nth, except it always returns nil if index ouf of bounds.
Like clojure.core/nth, except it always returns nil if index ouf of bounds.
(nth-key sm idx)
Returns key at idx
for sorted map sm
if it exists, otherwise nil.
Same as (some-> (nth sc idx nil) key)
Returns key at `idx` for sorted map `sm` if it exists, otherwise nil. Same as (some-> (nth sc idx nil) key)
(nth-val sc idx)
Returns val at idx
for sorted map sm
if it exists, otherwise nil.
Same as (some-> (nth sc idx nil) val)
Returns val at `idx` for sorted map `sm` if it exists, otherwise nil. Same as (some-> (nth sc idx nil) val)
(offset sc k n)
Takes the item that is n
items away from k
. If k
or the resulting item do not exist, returns nil.
e.g. (offset sc k -1) takes the previous item to key k
e.g. (offset sc k 1) takes the next item to key k
.
Takes the item that is `n` items away from `k`. If `k` or the resulting item do not exist, returns nil. e.g. (offset sc k -1) takes the previous item to key `k` e.g. (offset sc k 1) takes the next item to key `k`.
(offset-key sm k n)
Same as (some-> (offset sc k n) key)
Same as (some-> (offset sc k n) key)
(offset-val sm k n)
Same as (some-> (offset sc k n) val)
Same as (some-> (offset sc k n) val)
(rank-of sc k)
like avl/rank-of, but returns nil instead of -1 when item not found
like avl/rank-of, but returns nil instead of -1 when item not found
(tail-sorted sc n)
(tail-sorted sc n end-k)
Like tail
but returns an avl sorted collection.
Usually faster than (into (sorted-map) (tail sc n)),
except when the resulting collection is very small ~(< 10 items)
Like [[tail]] but returns an avl sorted collection. Usually faster than (into (sorted-map) (tail sc n)), except when the resulting collection is very small ~(< 10 items)
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close