Core implementation for high-performance unique identifiers.
Provides functions for generating and manipulating Flakes - 192-bit identifiers that combine nanosecond timestamps with high-entropy random data to ensure both uniqueness and monotonic ordering properties.
Core implementation for high-performance unique identifiers. Provides functions for generating and manipulating Flakes - 192-bit identifiers that combine nanosecond timestamps with high-entropy random data to ensure both uniqueness and monotonic ordering properties.
Internal implementation of high-performance time-ordered Flake IDs.
A Flake is a 192-bit (24-byte) identifier:
String representation uses custom base-64:
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
High-precision timestamp provider combining wall clock and monotonic timing.
This implementation anchors to the system wall clock at initialization, then uses monotonic timing to provide nanosecond-precision timestamps that maintain consistent intervals.
Key characteristics:
Note: This is not a high-precision wall clock replacement. While it provides nanosecond granularity, it can drift from true wall time over extended periods as monotonic clocks don't adjust for NTP synchronization.
Timestamp range extends to approximately year 2262 when using nanosecond precision in a long value.
High-precision timestamp provider combining wall clock and monotonic timing. This implementation anchors to the system wall clock at initialization, then uses monotonic timing to provide nanosecond-precision timestamps that maintain consistent intervals. Key characteristics: - Nanosecond resolution for timestamp generation - Monotonic properties within process lifetime - Wall-clock anchored for cross-system compatibility - Single global instance for consistency Note: This is not a high-precision wall clock replacement. While it provides nanosecond granularity, it can drift from true wall time over extended periods as monotonic clocks don't adjust for NTP synchronization. Timestamp range extends to approximately year 2262 when using nanosecond precision in a long value.
Unified interface for unique identifier generation.
This namespace provides a curated, client-friendly API exposing the most commonly used UUID and Flake operations. For advanced features and low-level operations, use the core namespaces directly:
com.vadelabs.uid.uuid.core for UUID internalscom.vadelabs.uid.flake.core for Flake internals(require '[com.vadelabs.uid.interface :as uid])
;; Random UUID (most common)
(uid/v4) ;=> #uuid "550e8400-e29b-41d4-a716-446655440000"
;; Time-ordered, sortable UUID (recommended for databases)
(uid/v7) ;=> #uuid "01890a5d-ac96-774b-bcce-b302099a8057"
;; Name-based UUID (deterministic)
(uid/v5 uid/+namespace-dns+ "example.com")
;; Generate Flake (192-bit, nanosecond precision)
(uid/flake) ;=> #flake/id "56S2f9LfyJJ52sY7JJuWL-etkrr2OBOC"
;; Generate as string directly
(uid/snowflake) ;=> "56S2f9Lg0JJ52sY7JJuWL-etkrr2OBOC"
This interface exposes:
Unified interface for unique identifier generation. This namespace provides a curated, client-friendly API exposing the most commonly used UUID and Flake operations. For advanced features and low-level operations, use the core namespaces directly: - `com.vadelabs.uid.uuid.core` for UUID internals - `com.vadelabs.uid.flake.core` for Flake internals ## Quick Start - UUID ```clojure (require '[com.vadelabs.uid.interface :as uid]) ;; Random UUID (most common) (uid/v4) ;=> #uuid "550e8400-e29b-41d4-a716-446655440000" ;; Time-ordered, sortable UUID (recommended for databases) (uid/v7) ;=> #uuid "01890a5d-ac96-774b-bcce-b302099a8057" ;; Name-based UUID (deterministic) (uid/v5 uid/+namespace-dns+ "example.com") ``` ## Quick Start - Flake ```clojure ;; Generate Flake (192-bit, nanosecond precision) (uid/flake) ;=> #flake/id "56S2f9LfyJJ52sY7JJuWL-etkrr2OBOC" ;; Generate as string directly (uid/snowflake) ;=> "56S2f9Lg0JJ52sY7JJuWL-etkrr2OBOC" ``` ## Design Philosophy This interface exposes: - ✓ High-frequency operations (generation, parsing, comparison) - ✓ Essential metadata extraction (timestamps from time-based IDs) - ✗ Low-level bit manipulation (use core namespaces) - ✗ Rarely-used UUID versions (v0, v8, squuid) - ✗ Internal implementation details
Lock-Free, Thread-safe Monotonic Clocks
Lock-Free, Thread-safe Monotonic Clocks
Core UUID generation and manipulation functions implementing RFC 9562.
Provides comprehensive support for all UUID versions (v0-v8) with efficient internal representation and conversion utilities.
Implementation inspired by clj-uuid by Dan Lentz: https://github.com/danlentz/clj-uuid Licensed under Eclipse Public License 1.0
Core UUID generation and manipulation functions implementing RFC 9562. Provides comprehensive support for all UUID versions (v0-v8) with efficient internal representation and conversion utilities. Implementation inspired by clj-uuid by Dan Lentz: https://github.com/danlentz/clj-uuid Licensed under Eclipse Public License 1.0
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |