aboutsummaryrefslogtreecommitdiff
path: root/src/std
diff options
context:
space:
mode:
Diffstat (limited to 'src/std')
-rw-r--r--src/std/file.c4
-rw-r--r--src/std/hash_map.c11
2 files changed, 13 insertions, 2 deletions
diff --git a/src/std/file.c b/src/std/file.c
index 84f4b0c..3ca94b0 100644
--- a/src/std/file.c
+++ b/src/std/file.c
@@ -176,6 +176,10 @@ typedef enum {
OTHER
} FileType;
+/*
+ TODO: Remove this and instead use fstat, and then read the file.
+ Otherwise this is not atomic and the file type can change between the calls
+*/
static CHECK_RESULT int file_get_type(const char *filepath, FileType *type) {
struct stat file_stats;
if(stat(filepath, &file_stats) == -1) {
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))