summaryrefslogtreecommitdiff
path: root/include/hashmap.h
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-11-01 23:46:08 -0400
committerIan Moffett <ian@osmora.org>2024-11-01 23:46:08 -0400
commita515dfb3b8f8e999362db7a6b52b3104c03b750a (patch)
treed0180f0cbc39d9c3e367af30791ad774e4d419ff /include/hashmap.h
Import quark sources
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'include/hashmap.h')
-rw-r--r--include/hashmap.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/include/hashmap.h b/include/hashmap.h
new file mode 100644
index 0000000..26dfc61
--- /dev/null
+++ b/include/hashmap.h
@@ -0,0 +1,34 @@
+/*
+ * Tiny hashmap implementation.
+ * Copyright (c) 2023-2024, Quinn Stephens and the OSMORA team.
+ * Provided under the BSD 3-Clause license.
+ */
+
+#ifndef _HASHMAP_H
+#define _HASHMAP_H
+
+#include <stddef.h>
+#include "list.h"
+#include "hash.h"
+
+struct hashmap_entry {
+ struct list_entry list_entry;
+ hash_t hash;
+};
+
+struct hashmap {
+ struct list *rows;
+ size_t n_rows;
+};
+
+static inline void
+hashmap_remove(struct hashmap_entry *entry)
+{
+ list_remove(&entry->list_entry);
+}
+
+void hashmap_add(struct hashmap *map, struct hashmap_entry *entry);
+struct hashmap_entry *hashmap_find(struct hashmap *map, hash_t hash);
+void hashmap_init(struct hashmap *map);
+
+#endif /* !_HASHMAP_H */