[feature] Enable Oid usage in hashtables (#11472)
This commit is contained in:
parent
b3d2cd738a
commit
a9aef65b2d
1 changed files with 9 additions and 1 deletions
|
|
@ -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'))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue