aboutsummaryrefslogtreecommitdiff
path: root/lib/uuid
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-09-06 14:47:45 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-09-06 14:47:45 -0400
commita8316252db95e3d77f9f0e9beb89cfcb4573d5b1 (patch)
treee5905bce9611e35ccb2f84481232fca0e657ff42 /lib/uuid
parenta0ac652cd1eebdc42425b34f1685f8cb20cb4eea (diff)
parent73246764f88f6f652316ee0c138a990d836698a7 (diff)
Merge branch 'main' into simplified-quotes
Diffstat (limited to 'lib/uuid')
-rw-r--r--lib/uuid/CHANGES.md5
-rw-r--r--lib/uuid/uuid.tm39
2 files changed, 0 insertions, 44 deletions
diff --git a/lib/uuid/CHANGES.md b/lib/uuid/CHANGES.md
deleted file mode 100644
index 42ae752c..00000000
--- a/lib/uuid/CHANGES.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# Version History
-
-## v1.0
-
-Initial version
diff --git a/lib/uuid/uuid.tm b/lib/uuid/uuid.tm
deleted file mode 100644
index f2be618e..00000000
--- a/lib/uuid/uuid.tm
+++ /dev/null
@@ -1,39 +0,0 @@
-use random_v1.0
-use time_v1.0
-
-lang UUID
- func v4(-> UUID) # Random UUID
- bytes := &random.bytes(16)
- bytes[7; unchecked] = 0x40 or (bytes[7; unchecked] and 0x0F)
- bytes[9; unchecked] = (Byte(random.int8(0x8, 0xB)) << 4) or (bytes[9; unchecked] and 0x0F)
- hex := "".join([b.hex() for b in bytes])
- uuid := "$(hex.slice(1, 8))-$(hex.slice(9, 12))-$(hex.slice(13, 16))-$(hex.slice(17, -1))"
- return UUID.from_text(uuid)
-
- func v7(-> UUID) # Timestamp + random UUID
- n := Time.now()
- timestamp := n.tv_sec*1000 + n.tv_usec/1_000
-
- bytes := [
- Byte((timestamp >> 40)),
- Byte((timestamp >> 32)),
- Byte((timestamp >> 24)),
- Byte((timestamp >> 16)),
- Byte((timestamp >> 8)),
- Byte(timestamp),
- (random.byte() and 0x0F) or 0x70,
- random.byte(),
- (random.byte() and 0x3F) or 0x80,
- random.byte() for _ in 7,
- ]
-
- hex := "".join([b.hex() for b in bytes])
- uuid := "$(hex.slice(1, 8))-$(hex.slice(9, 12))-$(hex.slice(13, 16))-$(hex.slice(17, -1))"
- return UUID.from_text(uuid)
-
-enum UUIDVersion(v4, v7)
-func main(version=UUIDVersion.v7)
- when version is v4
- say(UUID.v4().text)
- is v7
- say(UUID.v7().text)