From a515dfb3b8f8e999362db7a6b52b3104c03b750a Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 1 Nov 2024 23:46:08 -0400 Subject: Import quark sources Signed-off-by: Ian Moffett --- include/hashmap.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 include/hashmap.h (limited to 'include/hashmap.h') 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 +#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 */ -- cgit v1.2.3