code wiki / (root) / nx_uuid_v1.nx

nx_uuid_v1.nx

buildroot/runtime/nx_uuid_v1.nx

5288 B152 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

uuid.nx -- UUID v4 (random) + v7 (time-ordered) generators. RFC 4122 (v4) + draft-ietf-uuidrev-rfc4122bis (v7). 16-byte identifier, formatted as 36-char hex string with hyphens. v4 = 122 random bits + 6 deterministic version/variant bits. Use when you don't need lexicographic time-ordering. v7 = 48-bit Unix ms timestamp prefix + 74 random bits + 6 version/variant bits. Sorts lexicographically by creation time, which is huge for database indexes -- rows cluster instead of scattering, and clustered B-trees stay warm. Use in preference to v4 for new systems. Invariants: U1 Every byte of the non-version/variant space is from /dev/urandom (via rand.nx). No PRNG state persists; each UUID is an independent sample. U2 Version + variant bits exactly match the RFC specs at byte positions 6 (version) and 8 (variant). U3 v7 timestamp is milliseconds since epoch, big-endian in bytes 0..5. Enables lexicographic time-ordering. U4 Formatting is deterministic: lowercase hex, no prefix, exact dash placement at 8-4-4-4-12 positions.

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_rand.nx nx_hex_codec.nx nx_uuid_v1.nx

imports: nx_syscalls.nxnx_rand.nxnx_hex_codec.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 uuid_v4_string sys_mmap ↻ uuid_v4_bytes rand_bytes rand_open_urandom sys_openat_rd sys_read sys_close uuid_format sys_mmap ↻ hex_encode

structs

none

consts

none

functions

40func uuid_v4_bytes(out: *u8) -> i64
called by 1: uuid_v4_string calls 1: rand_bytes
55func uuid_v7_bytes(unix_ms: i64, out: *u8) -> i64
called by 1: uuid_v7_string calls 2: sys_mmaprand_bytes
85func uuid_format(bytes: *u8, out: *u8) -> i64
124func uuid_v4_string(out: *u8) -> i64
131func uuid_v7_string(unix_ms: i64, out: *u8) -> i64
139func main() -> i64