code wiki / (root) / ulid.nx

ulid.nx

buildroot/runtime/ulid.nx

6780 B190 linesdepth 4pulls 5 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

ulid.nx -- Universally Unique Lexicographically Sortable ID. Alizain Feerasta 2016 spec. Drop-in UUID replacement designed for databases + sortable indexes: - 128 bits, same width as UUID - First 48 bits: unix_ms timestamp (big-endian); sorts chronologically in a SQL ORDER BY or filesystem listing - Last 80 bits: cryptographic randomness - Encoded as 26 Crockford-32 characters (no hyphens) Examples: 01ARZ3NDEKTSV4RRFFQ69G5FAV 01H7TNAC9TZ42D8XGTVJBKRS7M Used by: modern databases (PostgreSQL ULID extension, MongoDB BSON_ULID), distributed systems needing time-ordered IDs, log correlation, event sourcing, request tracing. Composes rand.nx (80 bits of randomness) + crockford32.nx (canonical encoding). Time source is a caller-supplied unix_ms -- keeps the module pure/testable. Invariants: U1 Output = 26 ASCII chars, uppercase Crockford-32. U2 First 10 chars encode 48-bit timestamp; lex-sort and timestamp-sort agree within 2^48ms (~8900 years). U3 Same millisecond -> different IDs (random suffix differs); no strict monotonic-within-ms ordering guaranteed today (that's a future ULID_MONOTONIC variant).

dependencies 3 imports · 0 importers

syscalls.nx rand.nx crockford32.nx ulid.nx

imports: syscalls.nxrand.nxcrockford32.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main ulid_new ulid_bytes rand_bytes rand_open_urandom sys_read ulid_render c32_enc_char

structs

none

consts

35const ULID_LEN: i64 = 26
36const ULID_BYTES: i64 = 16

functions

39func ulid_bytes(unix_ms: i64, out: *u8) -> i64 {
called by 1: ulid_new calls 1: rand_bytes
59func ulid_render(bytes: *u8, out: *u8) -> i64 {
called by 1: ulid_new calls 1: c32_enc_char
127func ulid_new(unix_ms: i64, out: *u8) -> i64 {
called by 1: main calls 2: ulid_bytesulid_render
134func main() -> i64 {
calls 1: ulid_new