summaryrefslogtreecommitdiffstats
path: root/src/hashmap.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/hashmap.h')
-rw-r--r--src/hashmap.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/hashmap.h b/src/hashmap.h
new file mode 100644
index 0000000..1c9cd3e
--- /dev/null
+++ b/src/hashmap.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Copyright © 2010, Zed A. Shaw.
+ * Copyright © 2020 rsiddharth <s@ricketyspace.net>
+ */
+
+#ifndef _lcthw_Hashmap_h
+#define _lcthw_Hashmap_h
+
+#include <stdint.h>
+#include <darray.h>
+
+#define DEFAULT_NUMBER_OF_BUCKETS 100
+#define DEFAULT_NUMBER_OF_KEYS 50
+
+typedef int (*Hashmap_compare) (void *a, void *b);
+typedef uint32_t(*Hashmap_hash) (void *key);
+
+typedef struct Hashmap {
+ DArray *buckets;
+ Hashmap_compare compare;
+ Hashmap_hash hash;
+ int salt;
+} Hashmap;
+
+
+typedef struct HashmapNode {
+ void *key;
+ void *data;
+ uint32_t hash;
+} HashmapNode;
+
+typedef int (*Hashmap_traverse_cb) (HashmapNode *node);
+
+Hashmap *Hashmap_create(Hashmap_compare, Hashmap_hash);
+void Hashmap_destroy(Hashmap *map);
+
+int Hashmap_set(Hashmap *map, void *key, void *data);
+int Hashmap_set_fucked(Hashmap *map, void *key, void *data);
+void *Hashmap_get(Hashmap *map, void *key);
+
+int Hashmap_traverse(Hashmap *map, Hashmap_traverse_cb travers_cb);
+
+void *Hashmap_delete(Hashmap *map, void *key);
+
+DArray *Hashmap_keys(Hashmap *map);
+
+uint32_t fnv_hash(void *a);
+#endif