Liking cljdoc? Tell your friends :D

com.vadelabs.uid.uuid.core

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
raw docstring

+max+clj

The MAX UUID is a special form of sentinel UUID that is specified to have all 128 bits set to one.

The MAX UUID is a special form of sentinel UUID that is specified to have
all 128 bits set to one.
sourceraw docstring

+namespace-dns+clj

source

+namespace-oid+clj

source

+namespace-url+clj

source

+namespace-x500+clj

source

+null+clj

The NULL UUID is a special form of sentinel UUID that is specified to have all 128 bits set to zero.

The NULL UUID is a special form of sentinel UUID that is specified to have
all 128 bits set to zero.
sourceraw docstring

<clj

(< _)
(< x y)
(< x y & more)

Directly compare two or more UUIDs for < relation.

Directly compare two or more UUIDs for < relation.
sourceraw docstring

=clj

(= _)
(= x y)
(= x y & more)

Directly compare two or more UUIDs for equality.

Directly compare two or more UUIDs for equality.
sourceraw docstring

>clj

(> _)
(> x y)
(> x y & more)

Directly compare two or more UUIDs for > relation.

Directly compare two or more UUIDs for > relation.
sourceraw docstring

maxclj

(max)

Generates the v15 (maximum) UUID.

Generates the v15 (maximum) UUID.
sourceraw docstring

monotonic-timeclj

(monotonic-time)

Return a monotonic timestamp (guaranteed always increasing) based on the number of 100-nanosecond intervals elapsed since the adoption of the Gregorian calendar in the West, 12:00am Friday October 15, 1582 UTC.

Return a monotonic timestamp (guaranteed always increasing) based on
the number of 100-nanosecond intervals elapsed since the adoption of
the Gregorian calendar in the West, 12:00am Friday October 15, 1582 UTC.
sourceraw docstring

nullclj

(null)

Generates the v0 (null) UUID.

Generates the v0 (null) UUID.
sourceraw docstring

squuidclj

(squuid)

Generate a SQUUID (sequential, random) unique identifier.

Generate a SQUUID (sequential, random) unique identifier.
sourceraw docstring

uuid-string?clj

(uuid-string? s)
source

uuid-urn-string?clj

(uuid-urn-string? s)
source

uuid-vec?clj

(uuid-vec? v)
source

UUIDablecljprotocol

A UUIDable object directly represents a UUID.

A UUIDable object directly represents a UUID.

as-uuidclj

(as-uuid x)

Coerce the value 'x' to a UUID.

Coerce the value 'x' to a UUID.

uuidable?clj

(uuidable? x)

Return 'true' if 'x' can be coerced to UUID.

Return 'true' if 'x' can be coerced to UUID.
sourceraw docstring

UUIDNameBytescljprotocol

A mechanism intended for user-level extension that defines the decoding rules for the local-part representation of arbitrary Clojure / Java Objects when used for computing namespaced identifiers.

A mechanism intended for user-level extension that defines the
decoding rules for the local-part representation of arbitrary
Clojure / Java Objects when used for computing namespaced
identifiers.

as-byte-arrayclj

(as-byte-array x)

Extract a byte serialization that represents the 'name' of x, typically unique within a given namespace.

Extract a byte serialization that represents the 'name' of x,
typically unique within a given namespace.
sourceraw docstring

UUIDRfc4122cljprotocol

source

UUIDRfc9562cljprotocol

Protocol for RFC 9562 UUID operations.

Protocol for RFC 9562 UUID operations.

get-instantclj

(get-instant uuid)

Returns timestamp as java.util.Date, or nil for non-time-based UUIDs.

Returns timestamp as java.util.Date, or nil for non-time-based UUIDs.

get-unix-timeclj

(get-unix-time uuid)

Returns timestamp as milliseconds since Unix epoch, or nil for non-time-based UUIDs.

Returns timestamp as milliseconds since Unix epoch, or nil for non-time-based UUIDs.

get-nodeclj

(get-node uuid)

Returns node identifier: {:id long}

Returns node identifier: {:id long}

hash-codeclj

(hash-code uuid)

Returns the hash code as a long.

Returns the hash code as a long.

to-hex-stringclj

(to-hex-string uuid)

Returns 32-character hex string (no hyphens).

Returns 32-character hex string (no hyphens).

uuid=clj

(uuid= x y)

Returns true if UUIDs are equal.

Returns true if UUIDs are equal.

to-byte-arrayclj

(to-byte-array uuid)

Returns 16-byte array representation.

Returns 16-byte array representation.

uuid>clj

(uuid> x y)

Returns true if x > y (lexical byte-order comparison).

Returns true if x > y (lexical byte-order comparison).

null?clj

(null? uuid)

Returns true if this is the NULL UUID (all zeros).

Returns true if this is the NULL UUID (all zeros).

get-time-fieldsclj

(get-time-fields uuid)

Returns time components: {:low long :mid long :high long} Layout varies by version (v1 vs v6).

Returns time components: {:low long :mid long :high long}
Layout varies by version (v1 vs v6).

uuid<clj

(uuid< x y)

Returns true if x < y (lexical byte-order comparison).

Returns true if x < y (lexical byte-order comparison).

max?clj

(max? uuid)

Returns true if this is the MAX UUID (all ones).

Returns true if this is the MAX UUID (all ones).

to-stringclj

(to-string uuid)

Returns canonical string: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Returns canonical string: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

get-timestampclj

(get-timestamp uuid)

Extracts timestamp from time-based UUIDs (v1/v6/v7).

Returns:

  • v1/v6: 60-bit value (100-nanosecond intervals since Gregorian epoch 1582-10-15)
  • v7: 48-bit value (milliseconds since Unix epoch 1970-01-01)
  • Other versions: nil

Bit Layout Diagrams

UUID v1 (timestamp scattered across MSB)

MSB (64 bits): ┌─────────────────────────────────┬────────────────────┬──────────────┬──────┐ │ time_low (32 bits) │ time_mid (16 bits)│ time_hi (12) │ ver │ │ [bits 0-31 of timestamp] │ [bits 32-47] │ [bits 48-59] │ (4) │ └─────────────────────────────────┴────────────────────┴──────────────┴──────┘ Extract: time_low || time_mid || time_hi → 60-bit timestamp

UUID v6 (timestamp reordered for lexical sorting)

MSB (64 bits): ┌──────────────────┬────────────────────┬──────────────┬──────┐ │ time_high (32) │ time_mid (16) │ time_low (12)│ ver │ │ [bits 28-59] │ [bits 12-27] │ [bits 0-11] │ (4) │ └──────────────────┴────────────────────┴──────────────┴──────┘ Bits: [63──────────────────────────16][15────────────12][11─8][7────0] Extract: time_hi(28) || time_mid(12) || time_lo(12) → 60-bit timestamp

UUID v7 (Unix timestamp at start for optimal sorting)

MSB (64 bits): ┌─────────────────────────────────────────────────┬──────┬──────────────┐ │ unix_ts_ms (48 bits) │ ver │ rand (12) │ │ milliseconds since Unix epoch 1970-01-01 │ (4) │ │ └─────────────────────────────────────────────────┴──────┴──────────────┘ Bits: [63──────────────────────────────16][15──12][11────────────────0] Extract: bits [63:16] → 48-bit timestamp

Extracts timestamp from time-based UUIDs (v1/v6/v7).

Returns:
- v1/v6: 60-bit value (100-nanosecond intervals since Gregorian epoch 1582-10-15)
- v7: 48-bit value (milliseconds since Unix epoch 1970-01-01)
- Other versions: nil

## Bit Layout Diagrams

### UUID v1 (timestamp scattered across MSB)
MSB (64 bits):
┌─────────────────────────────────┬────────────────────┬──────────────┬──────┐
│        time_low (32 bits)       │  time_mid (16 bits)│ time_hi (12) │ ver  │
│  [bits 0-31 of timestamp]       │  [bits 32-47]      │ [bits 48-59] │ (4)  │
└─────────────────────────────────┴────────────────────┴──────────────┴──────┘
Extract: time_low || time_mid || time_hi → 60-bit timestamp

### UUID v6 (timestamp reordered for lexical sorting)
MSB (64 bits):
┌──────────────────┬────────────────────┬──────────────┬──────┐
│  time_high (32)  │  time_mid (16)     │ time_low (12)│ ver  │
│  [bits 28-59]    │  [bits 12-27]      │ [bits 0-11]  │ (4)  │
└──────────────────┴────────────────────┴──────────────┴──────┘
Bits: [63──────────────────────────16][15────────────12][11─8][7────0]
Extract: time_hi(28) || time_mid(12) || time_lo(12) → 60-bit timestamp

### UUID v7 (Unix timestamp at start for optimal sorting)
MSB (64 bits):
┌─────────────────────────────────────────────────┬──────┬──────────────┐
│          unix_ts_ms (48 bits)                   │ ver  │  rand (12)   │
│     milliseconds since Unix epoch 1970-01-01    │ (4)  │              │
└─────────────────────────────────────────────────┴──────┴──────────────┘
Bits: [63──────────────────────────────16][15──12][11────────────────0]
Extract: bits [63:16] → 48-bit timestamp

to-urn-stringclj

(to-urn-string uuid)

Returns URN format: urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Returns URN format: urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

get-versionclj

(get-version uuid)

Returns the version number (0-8).

Returns the version number (0-8).

get-wordsclj

(get-words uuid)

Returns UUID as two 64-bit words: {:high long :low long}

Returns UUID as two 64-bit words: {:high long :low long}

get-variantclj

(get-variant uuid)

Returns the variant number (typically 2 for RFC 9562).

Returns the variant number (typically 2 for RFC 9562).

uuid?clj

(uuid? x)

Returns true if x is a UUID instance.

Returns true if x is a UUID instance.

get-clock-fieldsclj

(get-clock-fields uuid)

Returns clock components: {:seq short :high long :low long} seq is non-nil only for v1/v6.

Returns clock components: {:seq short :high long :low long}
seq is non-nil only for v1/v6.

to-uriclj

(to-uri uuid)

Returns UUID as java.net.URI in URN format.

Returns UUID as java.net.URI in URN format.
sourceraw docstring

v0clj

(v0)

Generates the v0 (null) UUID.

Generates the v0 (null) UUID.
sourceraw docstring

v1clj

(v1)

Generate a v1 (time-based) unique identifier.

Generate a v1 (time-based) unique identifier.
sourceraw docstring

v3clj

(v3 context local-part)

Generate a v3 (name based, MD5 hash) UUID.

Generate a v3 (name based, MD5 hash) UUID.
sourceraw docstring

v4clj

(v4)
(v4 msb lsb)

Generate a v4 (random) UUID.

Generate a v4 (random) UUID.
sourceraw docstring

v5clj

(v5 context local-part)

Generate a v5 (name based, SHA1 hash) UUID.

Generate a v5 (name based, SHA1 hash) UUID.
sourceraw docstring

v6clj

(v6)

Generate a v6 (time-based), lexically sortable, unique identifier.

Generate a v6 (time-based), lexically sortable, unique identifier.
sourceraw docstring

v7clj

(v7)

Generate a v7 unix time-based, lexically sortable UUID.

Generate a v7 unix time-based, lexically sortable UUID.
sourceraw docstring

v8clj

(v8 msb lsb)

Generate a v8 custom UUID with user-defined data.

The v8 UUID format provides 122 bits of custom data:

MSB layout (64 bits total): ┌──────────────────────────────┬────┬──────────────────┐ │ custom data (48) │ver │ custom data (12)│ │ │ 8 │ │ └──────────────────────────────┴────┴──────────────────┘ bits: [63──────────16][15─12][11────────────────────0]

LSB layout (64 bits total): ┌─────┬──────────────────────────────────────────────┐ │var │ custom data (62 bits) │ │ 2 │ │ └─────┴──────────────────────────────────────────────┘ bits: [63-62][61────────────────────────────────────0]

Total custom data: 48 + 12 + 62 = 122 bits

Note: Version and variant bits are automatically set correctly. Any existing version/variant bits in the input will be overwritten.

Args: msb - Most significant 64 bits (bits 12-15 will be set to version 8) lsb - Least significant 64 bits (bits 62-63 will be set to variant 2)

Example: (v8 0x0123456789abcdef 0xfedcba9876543210) ;=> #uuid "01234567-89ab-8def-bfed-cba987654321" ^^^^ ^^^^ version variant

Generate a v8 custom UUID with user-defined data.

The v8 UUID format provides 122 bits of custom data:

MSB layout (64 bits total):
┌──────────────────────────────┬────┬──────────────────┐
│      custom data (48)        │ver │  custom data (12)│
│                              │ 8  │                  │
└──────────────────────────────┴────┴──────────────────┘
bits: [63──────────16][15─12][11────────────────────0]

LSB layout (64 bits total):
┌─────┬──────────────────────────────────────────────┐
│var  │         custom data (62 bits)                │
│ 2   │                                              │
└─────┴──────────────────────────────────────────────┘
bits: [63-62][61────────────────────────────────────0]

Total custom data: 48 + 12 + 62 = 122 bits

Note: Version and variant bits are automatically set correctly.
Any existing version/variant bits in the input will be overwritten.

Args:
  msb - Most significant 64 bits (bits 12-15 will be set to version 8)
  lsb - Least significant 64 bits (bits 62-63 will be set to variant 2)

Example:
  (v8 0x0123456789abcdef 0xfedcba9876543210)
  ;=> #uuid "01234567-89ab-8def-bfed-cba987654321"
                      ^^^^ ^^^^
                      version  variant
sourceraw docstring

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