ulid.nx
buildroot/runtime/ulid.nx
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
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
structs
| none |
consts
| 35 | const ULID_LEN: i64 = 26 |
| 36 | const ULID_BYTES: i64 = 16 |
functions
| 39 | func ulid_bytes(unix_ms: i64, out: *u8) -> i64 { |
| 59 | func ulid_render(bytes: *u8, out: *u8) -> i64 { |
| 127 | func ulid_new(unix_ms: i64, out: *u8) -> i64 { |
| 134 | func main() -> i64 {
calls 1: ulid_new |