summaryrefslogtreecommitdiff
path: root/qcom/qrtr/src/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'qcom/qrtr/src/hash.c')
-rw-r--r--qcom/qrtr/src/hash.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/qcom/qrtr/src/hash.c b/qcom/qrtr/src/hash.c
new file mode 100644
index 0000000..ecfbc0a
--- /dev/null
+++ b/qcom/qrtr/src/hash.c
@@ -0,0 +1,37 @@
+#include <string.h>
+#include "hash.h"
+
+unsigned int hash_mem(const void *data, unsigned int len)
+{
+ unsigned int h;
+ unsigned int i;
+
+ h = len;
+
+ for (i = 0; i < len; ++i)
+ h = ((h >> 27) ^ (h << 5)) ^ ((const unsigned char *)data)[i];
+
+ return h;
+}
+
+unsigned int hash_string(const char *value)
+{
+ return hash_mem(value, strlen(value));
+}
+
+unsigned int hash_u32(uint32_t value)
+{
+ return value * 2654435761UL;
+}
+
+unsigned int hash_u64(uint64_t value)
+{
+ return hash_u32(value & 0xffffffff) ^ hash_u32(value >> 32);
+}
+
+unsigned int hash_pointer(void *value)
+{
+ if (sizeof(value) == sizeof(uint64_t))
+ return hash_u64((long)value);
+ return hash_u32((long)value);
+}