added missing file
This commit is contained in:
parent
483213c389
commit
c0844f36f0
1 changed files with 17 additions and 0 deletions
17
src/shash.nim
Normal file
17
src/shash.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Simple hashing for the JS target.
|
||||||
|
|
||||||
|
type
|
||||||
|
Hash* = int
|
||||||
|
|
||||||
|
{.push checks: off.}
|
||||||
|
proc sdbmHash(hash: Hash, c: int): Hash {.inline.} =
|
||||||
|
return Hash(c) + (hash shl 6) + (hash shl 16) - hash
|
||||||
|
{.pop.}
|
||||||
|
|
||||||
|
proc charCodeAt(s: cstring; i: int): int {.importcpp: "#.charCodeAt(#)".}
|
||||||
|
|
||||||
|
template `&=`*(x: var Hash, c: int) = x = sdbmHash(x, c)
|
||||||
|
template `&=`*(x: var Hash, s: cstring) =
|
||||||
|
for i in 0..<s.len:
|
||||||
|
let c = charCodeAt(s, i)
|
||||||
|
x = sdbmHash(x, c)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue