diff options
author | Anton Kling <anton@kling.gg> | 2023-10-22 21:17:33 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-10-22 21:17:33 +0200 |
commit | 6f94dc4896089695811cbbf8ffe712f2113c8788 (patch) | |
tree | 615ebb6f191638bfab117d1380d66e66c50c6c64 /hashmap/hashmap.h | |
parent | 84c96e2ce3a4641699adafb41e1487538c2ac7d4 (diff) |
Fix submodules for the repo
Diffstat (limited to 'hashmap/hashmap.h')
-rw-r--r-- | hashmap/hashmap.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/hashmap/hashmap.h b/hashmap/hashmap.h new file mode 100644 index 0000000..40f146a --- /dev/null +++ b/hashmap/hashmap.h @@ -0,0 +1,39 @@ +// +// Copyright (C) 2022 by Anton Kling <anton@kling.gg> +// +// SPDX-License-Identifier: BSD-2-Clause +// +#ifndef HASHMAP_H +#define HASHMAP_H +#include <stddef.h> +#include <stdint.h> + +typedef struct LinkedList { + const char *key; + int key_allocated; + void *value; + void (*upon_deletion)(const char *, void *); + struct LinkedList *next; +} LinkedList; + +typedef struct HashMap { + LinkedList **entries; + size_t size; + size_t num_entries; + uint32_t (*hash_function)(const uint8_t *data, size_t len); +} HashMap; + +HashMap *hashmap_create(size_t size); +void hashmap_free(HashMap *m); + +// hashmap_add_entry() +// ------------------- +// This function adds a entry to the hashmap. The "key" passed to the +// hashmap will be allocated by default unless (do_not_allocate_key) is +// set to 1. +int hashmap_add_entry(HashMap *m, const char *key, void *value, + void (*upon_deletion)(const char *, void *), + int do_not_allocate_key); +void *hashmap_get_entry(HashMap *m, const char *key); +int hashmap_delete_entry(HashMap *m, const char *key); +#endif |