Added isZero proc
This commit is contained in:
parent
360ad9b082
commit
c6783039ac
3 changed files with 11 additions and 2 deletions
|
|
@ -16,6 +16,9 @@ proc hash*(uuid: UUID): Hash
|
|||
proc `==`*(x, y: UUID): bool
|
||||
## Returns true when the specified UUIDs are equal, false otherwise.
|
||||
|
||||
proc isZero*(uuid: UUID): bool
|
||||
## Returns ``true`` when the UUID is zero (not set), ``false`` otherwise.
|
||||
|
||||
proc genUUID*(): UUID =
|
||||
## Returns a random (v4) UUID.
|
||||
## Uses a thread-local cryptographically secure PRNG (ISAAC) seeded with
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ proc `==`*(x, y: UUID): bool =
|
|||
## Returns ``true`` when the specified UUIDs are equal, ``false`` otherwise.
|
||||
x.mostSigBits == y.mostSigBits and x.leastSigBits == y.leastSigBits
|
||||
|
||||
proc isZero*(uuid: UUID): bool =
|
||||
## Returns ``true`` when the UUID is zero (not set), ``false`` otherwise.
|
||||
uuid.mostSigBits == 0'i64 and uuid.leastSigBits == 0'i64
|
||||
|
||||
var rand {.threadvar.}: IsaacGenerator
|
||||
proc genUUID*(): UUID =
|
||||
## Returns a random (v4) UUID.
|
||||
|
|
@ -78,7 +82,9 @@ proc parseUUID*(s: string): UUID {.raises: [ValueError].} =
|
|||
result = UUID(mostSigBits: mostSigBits, leastSigBits: leastSigBits)
|
||||
|
||||
when isMainModule:
|
||||
let uuid = genUUID()
|
||||
var uuid: UUID
|
||||
assert(uuid.isZero())
|
||||
uuid = genUUID()
|
||||
let uuidStr = $uuid
|
||||
assert(uuidStr.len == 36)
|
||||
assert(uuidStr[14] == '4') # version
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[Package]
|
||||
name: "uuids"
|
||||
version: "0.1.1"
|
||||
version: "0.1.2"
|
||||
author: "Xored Software, Inc."
|
||||
description: "UUID library"
|
||||
license: "MIT"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue