code wiki / (root) / nx_ulid.nx

nx_ulid.nx

buildroot/runtime/nx_ulid.nx

6987 B198 linesdepth 3pulls 4 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

nx_syscalls.nx nx_rand.nx nx_crockford32.nx nx_ulid.nx

imports: nx_syscalls.nxnx_rand.nxnx_crockford32.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap ulid_new sys_mmap ↻ ulid_bytes rand_bytes rand_open_urandom sys_openat_rd sys_read sys_close ulid_render sys_mmap ↻ c32_enc_char

structs

none

consts

40const ULID_MAGIC_1777000000000: i64 = 1777000000000
41const ULID_MAGIC_1777000001000: i64 = 1777000001000
43const ULID_LEN: i64 = 26
44const ULID_BYTES: i64 = 16

functions

47func ulid_bytes(unix_ms: i64, out: *u8) -> i64
called by 1: ulid_new calls 1: rand_bytes
67func ulid_render(bytes: *u8, out: *u8) -> i64
called by 1: ulid_new calls 2: sys_mmapc32_enc_char
135func ulid_new(unix_ms: i64, out: *u8) -> i64
called by 1: main calls 3: sys_mmapulid_bytesulid_render
142func main() -> i64