summaryrefslogtreecommitdiff
path: root/src/runtime/c/gu/hash.h
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2012-01-20 13:41:10 +0000
committerkr.angelov <kr.angelov@gmail.com>2012-01-20 13:41:10 +0000
commit2eee382a62a909d5a3f2f5eda94f30fe68fd5335 (patch)
treeb0b0d513535895f244214aebf6358e172b8dce6d /src/runtime/c/gu/hash.h
parentb9728357126f8b9a6311cca17d9f0dcc2a7bfb9b (diff)
initial import of the C runtime
Diffstat (limited to 'src/runtime/c/gu/hash.h')
-rw-r--r--src/runtime/c/gu/hash.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/runtime/c/gu/hash.h b/src/runtime/c/gu/hash.h
new file mode 100644
index 000000000..e16c2f454
--- /dev/null
+++ b/src/runtime/c/gu/hash.h
@@ -0,0 +1,40 @@
+#ifndef GU_HASH_H_
+#define GU_HASH_H_
+
+#include <gu/fun.h>
+
+typedef GuWord GuHash;
+
+static inline GuHash
+gu_hash_ptr(void* ptr)
+{
+ return (GuHash) ptr;
+}
+
+
+static inline GuHash
+gu_hash_byte(GuHash h, uint8_t u)
+{
+ // Paul Larson's simple byte hash
+ return h * 101 + u;
+}
+
+
+GuHash
+gu_hash_bytes(GuHash h, const uint8_t* buf, size_t len);
+
+typedef const struct GuHasher GuHasher;
+
+struct GuHasher {
+ GuEquality eq;
+ GuHash (*hash)(GuHasher* self, const void* p);
+};
+
+
+extern GuHasher gu_int_hasher[1];
+
+extern GuHasher gu_addr_hasher[1];
+
+extern GuHasher gu_word_hasher[1];
+
+#endif // GU_HASH_H_