code wiki / (root) / nx_id.nx

nx_id.nx

buildroot/runtime/nx_id.nx

7011 B194 linesdepth 4pulls 4 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_id.nx -- monotonic IDs and 128-bit content addresses. Three ID surfaces, each with explicit guarantees: nx_seqid_next(ctx) monotonic 64-bit, unique per ctx since construction. Use for spans, requests, tasks -- any ordering you only need within one process lifetime. nx_uuid7(ctx) time-ordered 128-bit ID, RFC 9562 layout draft (UUIDv7). Two i64 outputs. The 48 high bits are unix-ms timestamp, remaining 80 bits are random+counter. Use across process boundaries when you need both ordering AND collision-resist. nx_xid_blake_short 8-byte digest of an arbitrary byte buffer using a tiny mixing function (xxhash-style). Use for content addressing where full SHA-256 is overkill. NOT cryptographic. For crypto use sha256.nx / sha512.nx. Why this file exists separately: ID generation is touched by every observability module (nx_log seq, nx_trace span_id, nx_metrics labels) and every IPC layer (request_id headers). Centralising the policy prevents drift -- e.g. one module producing 64-bit decimal, another 128-bit hex, another timestamp-prefixed. All flow through these three primitives. Design references: RFC 9562 (UUIDv7) -- time-ordered v7 layout Twitter Snowflake -- 64-bit time+machine+seq id ULID spec -- Crockford-base32 26-char id xxHash3 -- non-crypto fast mixing function

dependencies 2 imports · 0 importers

syscalls.nx nx_time.nx nx_id.nx

imports: syscalls.nxnx_time.nx

imported by: nobody (leaf or entry point)

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

main nx_id_new nx_seqid_next nx_uuid7_hi nx_clock_now_ns nx_seqid_next ↻ nx_uuid7_lo nx_id_xorshift nx_xid_short nx_id_xorshift ↻

structs

48struct NxIdCtx

consts

46const NX_MAGIC_1000000: i64 = 1000000
53const NX_IDCTX_BYTES: i64 = 16

functions

57func nx_id_new(seed: i64) -> *NxIdCtx
called by 1: main
68func nx_id_xorshift(ctx: *NxIdCtx) -> i64
called by 2: nx_uuid7_lomain
79func nx_seqid_next(ctx: *NxIdCtx) -> i64
called by 2: nx_uuid7_himain
94func nx_uuid7_hi(ctx: *NxIdCtx) -> i64
called by 1: main calls 2: nx_clock_now_nsnx_seqid_next
106func nx_uuid7_lo(ctx: *NxIdCtx) -> i64
called by 1: main calls 1: nx_id_xorshift
119func nx_xid_short(buf: *u8, len: i64) -> i64
called by 1: main
141func main() -> i64