Key

class Key : Comparable<Key>

A document key: an opaque byte string ordered as unsigned bytes.

Bytes rather than String because the ordering is the load-bearing part. An LSM-tree merges sorted runs, so the comparator is not a detail of the API — it is the one thing every segment ever written has to agree with, forever. Unsigned lexicographic order over bytes is the only choice that is stable under UTF-8: it makes key order agree with code-point order for text keys, while still accepting keys that are not text at all.

String.compareTo would have been the wrong comparator even for string keys — it compares UTF-16 units, so U+FF21 sorts before U+10000 in UTF-8 and after it in UTF-16. The Variant codec has the same rule for field names, for the same reason.

Keys are immutable; the bytes handed to of are copied, and toByteArray copies back out. An empty key is legal and sorts first.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val size: Int

Length of the key in bytes.

Functions

Link copied to clipboard
open operator override fun compareTo(other: Key): Int

Unsigned lexicographic comparison; the shorter key wins when one is a prefix of the other.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
operator fun get(index: Int): Byte

The byte at index.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

A copy of the key's bytes.

Link copied to clipboard
open override fun toString(): String

Printable ASCII is shown as text, anything else as hex.