aboutsummaryrefslogtreecommitdiff
path: root/include/std/hash_map.h
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-03-07 22:19:57 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit27718f093689dbd3decd7021eaa97327f578c8f3 (patch)
treec41ab4bb5727b22be35c1237279cfdfec0a27561 /include/std/hash_map.h
parent81b6004928015ced29b0b949e35753977aa17606 (diff)
Add hash map
Diffstat (limited to 'include/std/hash_map.h')
-rw-r--r--include/std/hash_map.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/std/hash_map.h b/include/std/hash_map.h
new file mode 100644
index 0000000..c36ecc4
--- /dev/null
+++ b/include/std/hash_map.h
@@ -0,0 +1,38 @@
+#ifndef AMALGAM_HASH_MAP_H
+#define AMALGAM_HASH_MAP_H
+
+#include "defs.h"
+#include "misc.h"
+#include "types.h"
+#include "buffer.h"
+#include "buffer_view.h"
+
+typedef struct HashMap HashMap;
+
+typedef int(*HashMapCompare)(const void *a, const void *b);
+typedef usize(*HashMapHash)(const u8 *data, usize size);
+
+struct HashMap {
+ ScopedAllocator *allocator; /* borrowed */
+ Buffer/*HashMapBucket*/ buckets;
+ usize type_size;
+ usize num_elements;
+ HashMapCompare compare_func;
+ HashMapHash hash_func;
+};
+
+CHECK_RESULT int hash_map_init(HashMap *self, ScopedAllocator *allocator, usize type_size, HashMapCompare compare_func, HashMapHash hash_func);
+/*
+Not thread-safe.
+Expected @value size to be @self->type_size.
+*/
+CHECK_RESULT int hash_map_insert(HashMap *self, BufferView key, void *value);
+/*
+Thread-safe unless @hash_map_insert is used in another thread at the same time.
+Expected @value size to be @self->type_size.
+*/
+CHECK_RESULT bool hash_map_get(HashMap *self, BufferView key, void *value);
+
+int hash_compare_string(const void *a, const void *b);
+
+#endif