aboutsummaryrefslogtreecommitdiff
path: root/src/std/hash_map.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/std/hash_map.c')
-rw-r--r--src/std/hash_map.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/std/hash_map.c b/src/std/hash_map.c
index 234f3e3..b4bd4c1 100644
--- a/src/std/hash_map.c
+++ b/src/std/hash_map.c
@@ -3,8 +3,13 @@
#include "../../include/std/mem.h"
#include <assert.h>
+/* Basic hash map implementation */
+
/*
-Basic hash map implementation. TODO: Improve performance
+ TODO: Improve performance. For example replace % with & by first making sure size of bucket is a power of two.
+ TODO: Instead of allocating space for the key, use the key data pointer and size directly.
+ TODO: Instead of allocating space for the data, allow the user to pass a pointer in the insert
+ method and use that directly.
*/
#define HASH_MAP_INITIAL_SIZE 8
@@ -109,6 +114,7 @@ static void hash_map_reorder_nodes(HashMap *self, usize end_index) {
usize bucket_size;
usize index;
+ /* TODO: bucket_end should be the old capacity. There is no need to reorder the new buckets */
bucket = (HashMapBucket*)self->buckets.data;
bucket_end = ((HashMapBucket*)self->buckets.data) + end_index;
bucket_size = buffer_get_size(&self->buckets, HashMapBucket);
@@ -177,6 +183,7 @@ int hash_map_insert(HashMap *self, BufferView key, void *value) {
return 0;
}
+/* TODO: Remove this. Use hash_map_get_ref instead */
bool hash_map_get(HashMap *self, BufferView key, void *value) {
#if 0
usize bucket_size;
@@ -235,7 +242,7 @@ bool hash_map_get_ref(HashMap *self, BufferView key, void **value) {
}
bool hash_map_contains(HashMap *self, BufferView key) {
- return hash_map_get(self, key, NULL);
+ return hash_map_get_ref(self, key, NULL);
}
#define MIN(a, b) ((a) < (b) ? (a) : (b))