Skip to content

Commit 90366b3

Browse files
update some comments and stuff
1 parent 5e4c7e6 commit 90366b3

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/clock.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
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
34

4-
@ns_per_ms 1_000_000
5+
@moduledoc false
56

67
# For macOS (Darwin) or Windows we would normally use 10 bits instead of 12.
78
# However, it would be an extra complexity and tradeoff of checking OS at
@@ -12,13 +13,13 @@ defmodule UUIDv7.Clock do
1213
# The count of possible values that fit in those bits (4096 or 2^12).
1314
@possible_values Bitwise.bsl(1, @sub_ms_bits)
1415

16+
@ns_per_ms 1_000_000
17+
1518
@minimal_step_ns div(@ns_per_ms, @possible_values) + 1
1619

1720
@doc """
1821
Get an always-ascending unix nanosecond timestamp.
1922
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
2223
2324
We use `:atomics` to ensure this works with concurrent executions without race
2425
conditions.

lib/uuidv7.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ defmodule UUIDv7 do
3333

3434
@variant 2
3535

36-
@ns_per_ms 1_000_000
37-
3836
# For macOS (Darwin) or Windows we would normally use 10 bits instead of 12.
3937
# However, it would be an extra complexity and tradeoff of checking OS at
4038
# runtime with some extra calcs, just for 2 bits of extra randomness for
@@ -43,6 +41,8 @@ defmodule UUIDv7 do
4341

4442
@possible_values Bitwise.bsl(1, @sub_ms_bits)
4543

44+
@ns_per_ms 1_000_000
45+
4646
@doc """
4747
Generates a version 7 UUID using submilliseconds for increased clock precision.
4848

0 commit comments

Comments
 (0)