diff --git a/README.md b/README.md index 3b7562f..2709427 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/uuids.nim b/src/uuids.nim index 106bf8e..6175e44 100644 --- a/src/uuids.nim +++ b/src/uuids.nim @@ -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 diff --git a/uuids.nimble b/uuids.nimble index c470a8e..2606324 100644 --- a/uuids.nimble +++ b/uuids.nimble @@ -1,6 +1,6 @@ [Package] name: "uuids" -version: "0.1.1" +version: "0.1.2" author: "Xored Software, Inc." description: "UUID library" license: "MIT"