add hash64 function
authorEugene Crosser <crosser@average.org>
Fri, 15 Mar 2019 08:49:22 +0000 (09:49 +0100)
committerEugene Crosser <crosser@average.org>
Fri, 15 Mar 2019 08:49:22 +0000 (09:49 +0100)
src/Makefile
src/hash64.c [new file with mode: 0644]
src/hash64.h [new file with mode: 0644]

index 2ce7e75d8d4841d4349fbf932c8f055ce3066d21..75e70a1b56ebe17817d630aa3f8132c7306d1bed 100644 (file)
@@ -2,7 +2,7 @@ CFLAGS = -pthread -Wall -I../include
 ARFLAGS = rcsv
 
 LIB = libpsmb.a
 ARFLAGS = rcsv
 
 LIB = libpsmb.a
-OBJ = psmb_socket.o
+OBJ = psmb_socket.o hash64.o
 
 all: $(LIB)
 
 
 all: $(LIB)
 
diff --git a/src/hash64.c b/src/hash64.c
new file mode 100644 (file)
index 0000000..fef4aa8
--- /dev/null
@@ -0,0 +1,11 @@
+/* Lifted from https://stackoverflow.com/a/13326345/2786866 */
+
+#include "hash64.h"
+
+uint64_t hash64(void *data, size_t size)
+{
+       uint64_t mix = 0, mulp = 2654435789;
+       for (int i = 0; i < size; i++)
+               mix += (((uint8_t *)data)[i] * mulp) ^ (mix >> 23);
+       return mix ^ (mix << 37);
+}
diff --git a/src/hash64.h b/src/hash64.h
new file mode 100644 (file)
index 0000000..d5e44d6
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef _HASH64_H
+
+#include <stdlib.h>
+#include <stdint.h>
+
+uint64_t hash64(void *data, size_t size);
+
+#endif