From 96974c2ed1528e447be34e4dae498e29c58e1242 Mon Sep 17 00:00:00 2001 From: Christian Bender Date: Sun, 24 Dec 2017 23:29:13 +0100 Subject: [PATCH] sdbm-hash algorithm I added the sdbm hash algorithm --- snippets/sdbm_hash.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 snippets/sdbm_hash.md diff --git a/snippets/sdbm_hash.md b/snippets/sdbm_hash.md new file mode 100644 index 000000000..e588ee5ad --- /dev/null +++ b/snippets/sdbm_hash.md @@ -0,0 +1,13 @@ + +This function implements the **sdbm** hash-algorithm. +It uses the charCodeAt-methode and the shift-operator. + +``` js +function sdbm(s) { + var hashCode = new Number(); + for (var i = 0; i < s.length; i++) { + hashCode = s.charCodeAt(i) + (hashCode << 6) + (hashCode << 16) - hashCode; + } + return hashCode; +} +``` \ No newline at end of file