Liking cljdoc? Tell your friends :D

xitdb.sorted

Public helpers for on-disk sorted collections (XITDBSortedMap / XITDBSortedSet) that go beyond clojure.core's in-memory sorted collections, exposing the rank-augmented B-tree's superpowers:

  • rank - O(log n) index of a key/member (inverse of indexed nth).
  • page - lazy ordered page starting at a rank (offset/limit).
  • from-index - lazy ordered seq starting at a rank.

These are the recommended way to build and paginate on-disk secondary indexes. For example, a timestamp -> id index over events:

(reset! db (sorted-map))
(doseq [e events]
  (swap! db assoc (:ts e) (:id e)))

;; serve the page [offset, offset+limit) in chronological order,
;; reading only that page from disk:
(xsorted/page @db offset limit)

;; or, starting from a known timestamp boundary:
(->> (subseq @db >= start-ts)
     (take limit))

Both rank and the pagination helpers work on XITDBSortedMap (yielding MapEntry pairs) and XITDBSortedSet (yielding members).

Public helpers for on-disk sorted collections (`XITDBSortedMap` /
`XITDBSortedSet`) that go beyond `clojure.core`'s in-memory sorted
collections, exposing the rank-augmented B-tree's superpowers:

  - `rank`  - O(log n) index of a key/member (inverse of indexed `nth`).
  - `page`  - lazy ordered page starting at a rank (offset/limit).
  - `from-index` - lazy ordered seq starting at a rank.

These are the recommended way to build and paginate on-disk secondary indexes.
For example, a timestamp -> id index over events:

    (reset! db (sorted-map))
    (doseq [e events]
      (swap! db assoc (:ts e) (:id e)))

    ;; serve the page [offset, offset+limit) in chronological order,
    ;; reading only that page from disk:
    (xsorted/page @db offset limit)

    ;; or, starting from a known timestamp boundary:
    (->> (subseq @db >= start-ts)
         (take limit))

Both `rank` and the pagination helpers work on `XITDBSortedMap` (yielding
`MapEntry` pairs) and `XITDBSortedSet` (yielding members).
raw docstring

xitdb.sorted-map

On-disk sorted map wrapper types, modelled on xitdb.hash-map.

XITDBSortedMap is the read view; XITDBWriteSortedMap is the mutable view used inside a transaction. Ordering is by the engine's unsigned byte comparison over order-preserving encoded keys (see xitdb.util.sorted-key).

Both views implement clojure.lang.Sorted/Indexed/Reversible (subseq, nth, rseq) on top of the rank-augmented B-tree, in addition to ascending ordered seq.

On-disk sorted map wrapper types, modelled on `xitdb.hash-map`.

`XITDBSortedMap` is the read view; `XITDBWriteSortedMap` is the mutable view
used inside a transaction. Ordering is by the engine's unsigned byte
comparison over order-preserving encoded keys (see `xitdb.util.sorted-key`).

Both views implement `clojure.lang.Sorted`/`Indexed`/`Reversible` (subseq,
nth, rseq) on top of the rank-augmented B-tree, in addition to ascending
ordered `seq`.
raw docstring

xitdb.sorted-set

On-disk sorted set wrapper types, modelled on xitdb.hash-set (set shape) and xitdb.sorted-map (the Sorted/Indexed/Reversible machinery).

A SORTED_SET is a SORTED_MAP with no values: each member is its own key. XITDBSortedSet is the read view; XITDBWriteSortedSet is the mutable view used inside a transaction. Ordering is by the engine's unsigned byte comparison over order-preserving encoded members (see xitdb.util.sorted-key).

On-disk sorted set wrapper types, modelled on `xitdb.hash-set` (set shape) and
`xitdb.sorted-map` (the `Sorted`/`Indexed`/`Reversible` machinery).

A `SORTED_SET` is a `SORTED_MAP` with no values: each member is its own key.
`XITDBSortedSet` is the read view; `XITDBWriteSortedSet` is the mutable view
used inside a transaction. Ordering is by the engine's unsigned byte
comparison over order-preserving encoded members (see `xitdb.util.sorted-key`).
raw docstring

xitdb.util.sorted-key

Order-preserving, reversible key codec for on-disk sorted maps/sets.

Unlike hash maps (which SHA-1-hash their keys), sorted collections store the real key bytes so they can be recovered on read and compared by the engine's unsigned lexicographic byte comparison (Arrays.compareUnsigned). The codec must therefore be:

  1. reversible - decode-key (encode-key k) == k
  2. order-preserving - sign(compareUnsigned (encode a) (encode b)) == sign(compare a b) for any two keys.

Every encoding carries a leading 1-byte type tag. The tag both identifies the type on decode and establishes a total order across types, so heterogeneous keys never throw.

Supported key types: string, keyword, boolean, char, long, double, UUID, Instant and Date. Strings encode as their UTF-8 bytes (already code-point ordered); keywords use a flag + namespace + name layout so they sort like Clojure's default comparator (see keyword->bytes); numeric/temporal/UUID keys use order-preserving big-endian encodings.

Order-preserving, reversible key codec for on-disk sorted maps/sets.

Unlike hash maps (which SHA-1-hash their keys), sorted collections store the
real key bytes so they can be recovered on read and compared by the engine's
unsigned lexicographic byte comparison (`Arrays.compareUnsigned`). The codec
must therefore be:

  1. reversible  - `decode-key (encode-key k)` == k
  2. order-preserving - `sign(compareUnsigned (encode a) (encode b))`
                        == `sign(compare a b)` for any two keys.

Every encoding carries a leading 1-byte type tag. The tag both identifies the
type on decode and establishes a total order across types, so heterogeneous
keys never throw.

Supported key types: string, keyword, boolean, char, long, double, UUID,
Instant and Date. Strings encode as their UTF-8 bytes (already code-point
ordered); keywords use a flag + namespace + name layout so they sort like
Clojure's default comparator (see `keyword->bytes`); numeric/temporal/UUID
keys use order-preserving big-endian encodings.
raw docstring

xitdb.util.sorted-operations

Bridges the XITDBSorted* wrapper types to the Java Read/WriteSortedMap. Keys are encoded/decoded through xitdb.util.sorted-key (order-preserving, reversible) rather than hashed, so the real key is recoverable on read.

Bridges the XITDBSorted* wrapper types to the Java Read/WriteSortedMap.
Keys are encoded/decoded through `xitdb.util.sorted-key` (order-preserving,
reversible) rather than hashed, so the real key is recoverable on read.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close