summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorHitesh Jasani <hitesh.jasani@gmail.com>2019-06-11 09:06:46 -0400
committerAndreas Rumpf <rumpf_a@web.de>2019-06-11 15:06:46 +0200
commita9aef65b2d761e0e29d1dde681b857dda49248da (patch)
treecf379dd40670b3f9801a0d9feb31690c9a3641da /lib
parentb3d2cd738a59aa07eea7cb69e944c7db9eed6a86 (diff)
downloadNim-a9aef65b2d761e0e29d1dde681b857dda49248da.tar.gz
[feature] Enable Oid usage in hashtables (#11472)
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/oids.nim10
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'))