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:
decode-key (encode-key k) == ksign(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.(decode-key ba)Decodes a byte array produced by encode-key back to the Clojure key.
Decodes a byte array produced by `encode-key` back to the Clojure key.
(encode-key k)Encodes Clojure key k to an order-preserving, reversible byte array.
Encodes Clojure key `k` to an order-preserving, reversible byte array.
A java.util.Comparator consistent with the engine's natural ordering:
compares two keys by Arrays.compareUnsigned over their encoded bytes. Use
this (not clojure.core/compare) so subseq/rsubseq bound checks agree with
on-disk order across all supported types, including heterogeneous keys.
A `java.util.Comparator` consistent with the engine's natural ordering: compares two keys by `Arrays.compareUnsigned` over their encoded bytes. Use this (not `clojure.core/compare`) so `subseq`/`rsubseq` bound checks agree with on-disk order across all supported types, including heterogeneous keys.
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 |