diff options
| author | benj <benj@rse8.com> | 2017-06-16 01:20:02 -0700 |
|---|---|---|
| committer | benj <benj@rse8.com> | 2017-06-16 01:20:02 -0700 |
| commit | 14adc6a1d769e22958496d570b7f25b68cc86969 (patch) | |
| tree | 6754de138c6d59bbfce8d5a3b732891d5a5e220b /src/algo/hash.c | |
| parent | dee453b6473354786871a9b0b123d676ef1eb5cc (diff) | |
| download | workbench-master.tar workbench-master.tar.gz workbench-master.tar.bz2 workbench-master.tar.lz workbench-master.tar.xz workbench-master.tar.zst workbench-master.zip | |
Diffstat (limited to 'src/algo/hash.c')
| -rw-r--r-- | src/algo/hash.c | 22 |
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; +} |
