diff options
Diffstat (limited to 'include/hashmap.h')
-rw-r--r-- | include/hashmap.h | 34 |
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 */ |