[backport] run nimpretty on hashes

This commit is contained in:
narimiran 2019-09-27 11:03:55 +02:00
commit 15895ebc3f
5 changed files with 16 additions and 12 deletions

View file

@ -112,7 +112,8 @@ template encodeInternal(s: typed, lineLen: int, newLine: string): untyped =
#assert(r == result.len) #assert(r == result.len)
discard discard
proc encode*[T: SomeInteger|char](s: openArray[T], lineLen = 75, newLine=""): string = proc encode*[T: SomeInteger|char](s: openArray[T], lineLen = 75,
newLine = ""): string =
## Encodes ``s`` into base64 representation. After ``lineLen`` characters, a ## Encodes ``s`` into base64 representation. After ``lineLen`` characters, a
## ``newline`` is added. ## ``newline`` is added.
## ##
@ -128,7 +129,7 @@ proc encode*[T: SomeInteger|char](s: openArray[T], lineLen = 75, newLine=""): st
assert encode([1, 2, 3, 4, 5]) == "AQIDBAU=" assert encode([1, 2, 3, 4, 5]) == "AQIDBAU="
encodeInternal(s, lineLen, newLine) encodeInternal(s, lineLen, newLine)
proc encode*(s: string, lineLen = 75, newLine=""): string = proc encode*(s: string, lineLen = 75, newLine = ""): string =
## Encodes ``s`` into base64 representation. After ``lineLen`` characters, a ## Encodes ``s`` into base64 representation. After ``lineLen`` characters, a
## ``newline`` is added. ## ``newline`` is added.
## ##
@ -208,5 +209,5 @@ when isMainModule:
for t in items(tests): for t in items(tests):
assert decode(encode(t)) == t assert decode(encode(t)) == t
assert decode(encode(t, lineLen=40)) == t assert decode(encode(t, lineLen = 40)) == t
assert decode(encode(t, lineLen=76)) == t assert decode(encode(t, lineLen = 76)) == t

View file

@ -45,7 +45,7 @@
## * `tables module <tables.html>`_ for hash tables ## * `tables module <tables.html>`_ for hash tables
type type
Hash* = int ## A hash value. Hash tables using these values should Hash* = int ## A hash value. Hash tables using these values should
## always have a size of a power of two and can use the ``and`` ## always have a size of a power of two and can use the ``and``
## operator instead of ``mod`` for truncation of the hash value. ## operator instead of ``mod`` for truncation of the hash value.
@ -451,7 +451,7 @@ when isMainModule:
doAssert hashIgnoreStyle("aa_bb_AAaa1234") == hashIgnoreCase("aaBBAAAa1234") doAssert hashIgnoreStyle("aa_bb_AAaa1234") == hashIgnoreCase("aaBBAAAa1234")
block smallSize: # no multibyte hashing block smallSize: # no multibyte hashing
let let
xx = @['H','i'] xx = @['H', 'i']
ii = @[72'u8, 105] ii = @[72'u8, 105]
ss = "Hi" ss = "Hi"
doAssert hash(xx) == hash(ii) doAssert hash(xx) == hash(ii)
@ -460,8 +460,8 @@ when isMainModule:
doAssert hash(ss) == hash(ss, 0, ss.high) doAssert hash(ss) == hash(ss, 0, ss.high)
block largeSize: # longer than 4 characters block largeSize: # longer than 4 characters
let let
xx = @['H','e','l','l','o'] xx = @['H', 'e', 'l', 'l', 'o']
xxl = @['H','e','l','l','o','w','e','e','n','s'] xxl = @['H', 'e', 'l', 'l', 'o', 'w', 'e', 'e', 'n', 's']
ssl = "Helloweens" ssl = "Helloweens"
doAssert hash(xxl) == hash(ssl) doAssert hash(xxl) == hash(ssl)
doAssert hash(xxl) == hash(xxl, 0, xxl.high) doAssert hash(xxl) == hash(xxl, 0, xxl.high)

View file

@ -172,7 +172,8 @@ proc transform(buffer: pointer, state: var MD5State) =
state[3] = state[3] + d state[3] = state[3] + d
proc md5Init*(c: var MD5Context) {.raises: [], tags: [], gcsafe.} proc md5Init*(c: var MD5Context) {.raises: [], tags: [], gcsafe.}
proc md5Update*(c: var MD5Context, input: cstring, len: int) {.raises: [], tags: [], gcsafe.} proc md5Update*(c: var MD5Context, input: cstring, len: int) {.raises: [],
tags: [], gcsafe.}
proc md5Final*(c: var MD5Context, digest: var MD5Digest) {.raises: [], tags: [], gcsafe.} proc md5Final*(c: var MD5Context, digest: var MD5Digest) {.raises: [], tags: [], gcsafe.}

View file

@ -16,7 +16,8 @@ proc newMersenneTwister*(seed: uint32): MersenneTwister =
result.index = 0 result.index = 0
result.mt[0] = seed result.mt[0] = seed
for i in 1'u32 .. 623'u32: for i in 1'u32 .. 623'u32:
result.mt[i] = (0x6c078965'u32 * (result.mt[i-1] xor (result.mt[i-1] shr 30'u32)) + i) result.mt[i] = (0x6c078965'u32 * (result.mt[i-1] xor
(result.mt[i-1] shr 30'u32)) + i)
proc generateNumbers(m: var MersenneTwister) = proc generateNumbers(m: var MersenneTwister) =
for i in 0..623: for i in 0..623:

View file

@ -18,14 +18,15 @@
import hashes, times, endians import hashes, times, endians
type type
Oid* = object ## an OID Oid* = object ## an OID
time: int32 ## time: int32 ##
fuzz: int32 ## fuzz: int32 ##
count: int32 ## count: int32 ##
proc `==`*(oid1: Oid, oid2: Oid): bool = proc `==`*(oid1: Oid, oid2: Oid): bool =
## Compare two Mongo Object IDs for equality ## Compare two Mongo Object IDs for equality
return (oid1.time == oid2.time) and (oid1.fuzz == oid2.fuzz) and (oid1.count == oid2.count) return (oid1.time == oid2.time) and (oid1.fuzz == oid2.fuzz) and
(oid1.count == oid2.count)
proc hash*(oid: Oid): Hash = proc hash*(oid: Oid): Hash =
## Generate hash of Oid for use in hashtables ## Generate hash of Oid for use in hashtables