From c0844f36f0277c8c2cc49d2ca988fb547156d947 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 13 Apr 2017 09:41:22 +0200 Subject: [PATCH] added missing file --- src/shash.nim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/shash.nim diff --git a/src/shash.nim b/src/shash.nim new file mode 100644 index 0000000..c387e22 --- /dev/null +++ b/src/shash.nim @@ -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..