Liking cljdoc? Tell your friends :D

com.vadelabs.uid.flake.impl

Internal implementation of high-performance time-ordered Flake IDs.

Architecture

A Flake is a 192-bit (24-byte) identifier:

  • 64-bit nanosecond-precision timestamp
  • 128-bit random component (two 64-bit longs)

Encoding

String representation uses custom base-64:

  • Alphabet: -0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
  • 24 bytes → 32 characters
  • Preserves lexical ordering
  • URL-safe (no +, / characters)

Thread Safety

  • ThreadLocal RNG for lock-free generation
  • Nanoclock provides monotonicity within thread
  • Cross-thread ordering via timestamp component

Performance

  • Generation: ~300ns (no locks, pure CPU)
  • Encoding: ~500ns (custom algorithm)
  • Parsing: ~600ns (with validation)

This is an internal namespace. Use com.vadelabs.uid.flake.core for public API.

Implementation inspired by μ/log (mulog) by Bruno Bonacci: https://github.com/BrunoBonacci/mulog/blob/master/mulog-core/src/com/brunobonacci/mulog/flakes.clj Licensed under Apache License 2.0

Internal implementation of high-performance time-ordered Flake IDs.

## Architecture

A Flake is a 192-bit (24-byte) identifier:
- 64-bit nanosecond-precision timestamp
- 128-bit random component (two 64-bit longs)

## Encoding

String representation uses custom base-64:
- Alphabet: -0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
- 24 bytes → 32 characters
- Preserves lexical ordering
- URL-safe (no +, / characters)

## Thread Safety

- ThreadLocal RNG for lock-free generation
- Nanoclock provides monotonicity within thread
- Cross-thread ordering via timestamp component

## Performance

- Generation: ~300ns (no locks, pure CPU)
- Encoding: ~500ns (custom algorithm)
- Parsing: ~600ns (with validation)

This is an internal namespace. Use com.vadelabs.uid.flake.core for public API.

Implementation inspired by μ/log (mulog) by Bruno Bonacci:
https://github.com/BrunoBonacci/mulog/blob/master/mulog-core/src/com/brunobonacci/mulog/flakes.clj
Licensed under Apache License 2.0
raw docstring

flakeclj

(flake)
source

flake->bytesclj

(flake->bytes f)
source

flake->hexclj

(flake->hex f)
source

flake->stringclj

(flake->string f)
source

flake?clj

(flake? x)
source

make-flakeclj

(make-flake byte-data)
(make-flake timestamp-nanos random-high random-low)
source

nanos-per-milliclj

source

parse-flakeclj

(parse-flake flake-str)
source

timestamp-nanosclj

(timestamp-nanos f)
source

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close