From 369ecbcd56ad418f8fd91d742eca555405490719 Mon Sep 17 00:00:00 2001 From: Christian Bender Date: Sun, 24 Dec 2017 23:30:22 +0100 Subject: [PATCH] added sdbm hash algorithm I added the sdbm hash algorithm as a function. --- 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