ref: a0f5762d967c3c09e6d7303e238976c6c9835ed5
parent: 765f64dff7a9c6adef091a8d686be2cf09ad15cb
author: qwx <qwx@sciops.net>
date: Fri Jul 7 07:36:39 EDT 2023
hash: add djb hash algorithm
--- /dev/null
+++ b/hash/djb.c
@@ -1,0 +1,15 @@
+/* Daniel J. Bernstein hashing algorithm, retrieved from:
+ * http://www.partow.net/programming/hashfunctions/index.html */
+
+unsigned int djbhash(const char* str, unsigned int length)
+{
+ unsigned int hash = 5381;
+ unsigned int i = 0;
+
+ for (i = 0; i < length; ++str, ++i)
+ {
+ hash = ((hash << 5) + hash) + (*str);
+ }
+
+ return hash;
+}