summaryrefslogtreecommitdiff
path: root/src/runtime/c/gu/hash.c
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.c
parentb9728357126f8b9a6311cca17d9f0dcc2a7bfb9b (diff)
initial import of the C runtime
Diffstat (limited to 'src/runtime/c/gu/hash.c')
-rw-r--r--src/runtime/c/gu/hash.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/runtime/c/gu/hash.c b/src/runtime/c/gu/hash.c
new file mode 100644
index 000000000..1666263e6
--- /dev/null
+++ b/src/runtime/c/gu/hash.c
@@ -0,0 +1,77 @@
+#include <gu/hash.h>
+
+GuHash
+gu_hash_bytes(GuHash h, const uint8_t* buf, size_t len)
+{
+ for (size_t n = 0; n < len; n++) {
+ h = gu_hash_byte(h, buf[n]);
+ }
+ return h;
+}
+
+static bool
+gu_int_eq_fn(GuEquality* self, const void* p1, const void* p2)
+{
+ (void) self;
+ const int* ip1 = p1;
+ const int* ip2 = p2;
+ return *ip1 == *ip2;
+}
+
+static GuHash
+gu_int_hash_fn(GuHasher* self, const void* p)
+{
+ (void) self;
+ return (GuHash) *(const int*) p;
+}
+
+GuHasher gu_int_hasher[1] = {
+ {
+ { gu_int_eq_fn },
+ gu_int_hash_fn
+ }
+};
+
+static bool
+gu_addr_eq_fn(GuEquality* self, const void* p1, const void* p2)
+{
+ (void) self;
+ return (p1 == p2);
+}
+
+static GuHash
+gu_addr_hash_fn(GuHasher* self, const void* p)
+{
+ (void) self;
+ return (GuHash) (uintptr_t) p;
+}
+
+GuHasher gu_addr_hasher[1] = {
+ {
+ { gu_addr_eq_fn },
+ gu_addr_hash_fn
+ }
+};
+
+static bool
+gu_word_eq_fn(GuEquality* self, const void* p1, const void* p2)
+{
+ (void) self;
+ const GuWord* wp1 = p1;
+ const GuWord* wp2 = p2;
+ return (*wp1 == *wp2);
+}
+
+static GuHash
+gu_word_hash_fn(GuHasher* self, const void* p)
+{
+ (void) self;
+ return (GuHash) (uintptr_t) p;
+}
+
+GuHasher gu_word_hasher[1] = {
+ {
+ { gu_word_eq_fn },
+ gu_word_hash_fn
+ }
+};