From 203fbb778e9cfe3aff8b4dee6da9a103a171ca0e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 28 Feb 2020 16:58:49 +0100 Subject: Update hash map comments --- src/std/hash_map.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/std/hash_map.c') 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 +/* 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)) -- cgit v1.2.3