Skip to content

compareBytes(left, right): -1 | 0 | 1

Defined in: packages/key-encoding/src/bytes.ts:12

Compare two byte strings in unsigned lexicographic order, the order an encoded key sorts in.

A proper prefix sorts before every longer string that extends it. The result is -1, 0, or 1, so the function is an Order<Uint8Array> for knotkit/heap, knotkit/ordered-map, knotkit/sorted-merge, or Array.prototype.sort.

Runs in O(min(left.byteLength, right.byteLength)) and does not validate its arguments, because it sits on the hot path of every comparison-based structure; pass Uint8Array values.

Uint8Array

Uint8Array

-1 | 0 | 1