mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 05:20:31 +00:00
[feature] Enable Oid usage in hashtables (#11472)
This commit is contained in:
committed by
Andreas Rumpf
parent
b3d2cd738a
commit
a9aef65b2d
@@ -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'))
|
||||
|
||||
Reference in New Issue
Block a user