aboutsummaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-01-19 19:06:09 +0100
committerHugo Hörnquist <hugo@hornquist.se>2019-01-19 19:06:14 +0100
commitc42c2834d8c7b5d81465b9d9d127d8384151b9cb (patch)
tree53b1a8eb0368d5f91525604eea2c3173083c1955 /hash.c
parentCan now parse entire directory in one go. (diff)
downloadcalp-c42c2834d8c7b5d81465b9d9d127d8384151b9cb.tar.gz
calp-c42c2834d8c7b5d81465b9d9d127d8384151b9cb.tar.xz
[BROKEN] Work on adding hash tables.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/hash.c b/hash.c
new file mode 100644
index 00000000..47775b59
--- /dev/null
+++ b/hash.c
@@ -0,0 +1,15 @@
+#include "hash.h"
+
+/*
+ * http://www.cse.yorku.ca/~oz/hash.html
+ * djb2 from above url.
+ */
+unsigned long hash(char* str) {
+ unsigned long hash = 5381;
+ int c;
+
+ while ( (c = *str++) )
+ hash = ((hash << 5) + hash) + c;
+
+ return hash;
+}