File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change 1
1
defmodule UUIDv7.Clock do
2
- @ moduledoc false
2
+ # See the Postgres version (in `C`):
3
+ # https://github.com/postgres/postgres/blob/0e42d31b0b2273c376ce9de946b59d155fac589c/src/backend/utils/adt/uuid.c#L480
3
4
4
- @ ns_per_ms 1_000_000
5
+ @ moduledoc false
5
6
6
7
# For macOS (Darwin) or Windows we would normally use 10 bits instead of 12.
7
8
# However, it would be an extra complexity and tradeoff of checking OS at
@@ -12,13 +13,13 @@ defmodule UUIDv7.Clock do
12
13
# The count of possible values that fit in those bits (4096 or 2^12).
13
14
@ possible_values Bitwise . bsl ( 1 , @ sub_ms_bits )
14
15
16
+ @ ns_per_ms 1_000_000
17
+
15
18
@ minimal_step_ns div ( @ ns_per_ms , @ possible_values ) + 1
16
19
17
20
@ doc """
18
21
Get an always-ascending unix nanosecond timestamp.
19
22
20
- This is a re-implementation of the Postgres version here (in `C`):
21
- https://github.com/postgres/postgres/blob/0e42d31b0b2273c376ce9de946b59d155fac589c/src/backend/utils/adt/uuid.c#L480
22
23
23
24
We use `:atomics` to ensure this works with concurrent executions without race
24
25
conditions.
Original file line number Diff line number Diff line change @@ -33,8 +33,6 @@ defmodule UUIDv7 do
33
33
34
34
@ variant 2
35
35
36
- @ ns_per_ms 1_000_000
37
-
38
36
# For macOS (Darwin) or Windows we would normally use 10 bits instead of 12.
39
37
# However, it would be an extra complexity and tradeoff of checking OS at
40
38
# runtime with some extra calcs, just for 2 bits of extra randomness for
@@ -43,6 +41,8 @@ defmodule UUIDv7 do
43
41
44
42
@ possible_values Bitwise . bsl ( 1 , @ sub_ms_bits )
45
43
44
+ @ ns_per_ms 1_000_000
45
+
46
46
@ doc """
47
47
Generates a version 7 UUID using submilliseconds for increased clock precision.
48
48
You can’t perform that action at this time.
0 commit comments