aboutsummaryrefslogtreecommitdiff
path: root/src/algo/hash.c
diff options
context:
space:
mode:
authorbenj <benj@rse8.com>2017-06-16 01:20:02 -0700
committerbenj <benj@rse8.com>2017-06-16 01:20:02 -0700
commit14adc6a1d769e22958496d570b7f25b68cc86969 (patch)
tree6754de138c6d59bbfce8d5a3b732891d5a5e220b /src/algo/hash.c
parentdee453b6473354786871a9b0b123d676ef1eb5cc (diff)
downloadworkbench-14adc6a1d769e22958496d570b7f25b68cc86969.tar
workbench-14adc6a1d769e22958496d570b7f25b68cc86969.tar.gz
workbench-14adc6a1d769e22958496d570b7f25b68cc86969.tar.bz2
workbench-14adc6a1d769e22958496d570b7f25b68cc86969.tar.lz
workbench-14adc6a1d769e22958496d570b7f25b68cc86969.tar.xz
workbench-14adc6a1d769e22958496d570b7f25b68cc86969.tar.zst
workbench-14adc6a1d769e22958496d570b7f25b68cc86969.zip
add unity testing fmwk and simple hash fn demonstrationHEADmaster
Diffstat (limited to '')
-rw-r--r--src/algo/hash.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/algo/hash.c b/src/algo/hash.c
new file mode 100644
index 0000000..c8ba66d
--- /dev/null
+++ b/src/algo/hash.c
@@ -0,0 +1,22 @@
+#include "hash.h"
+#include <stdint.h>
+
+uint64_t xor64_hash(uint64_t const *const bytes, size_t size) {
+ uint64_t result = 0;
+
+ while (size != 0) {
+ result ^= bytes[size - 1];
+ size--;
+ }
+
+ return result;
+}
+
+uint64_t djb2_hash(char const *const bytes, size_t size) {
+ uint64_t hash = 5381;
+ for (size_t i = 0; i < size; i++) {
+ hash = ((hash << 5) + hash) + bytes[i];
+ }
+
+ return hash;
+}