diff options
Diffstat (limited to 'lib/pure/oids.nim')
-rw-r--r-- | lib/pure/oids.nim | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/pure/oids.nim b/lib/pure/oids.nim index 3aee3941d..f3f50c25d 100644 --- a/lib/pure/oids.nim +++ b/lib/pure/oids.nim @@ -15,7 +15,7 @@ ## This implementation calls ``math.randomize()`` for the first call of ## ``genOid``. -import times, endians +import hashes, times, endians type Oid* = object ## an OID @@ -27,6 +27,14 @@ proc `==`*(oid1: Oid, oid2: Oid): bool = ## Compare two Mongo Object IDs for equality return (oid1.time == oid2.time) and (oid1.fuzz == oid2.fuzz) and (oid1.count == oid2.count) +proc hash*(oid: Oid): Hash = + ## Generate hash of Oid for use in hashtables + var h: Hash = 0 + h = h !& hash(oid.time) + h = h !& hash(oid.fuzz) + h = h !& hash(oid.count) + result = !$h + proc hexbyte*(hex: char): int = case hex of '0'..'9': result = (ord(hex) - ord('0')) |