aboutsummaryrefslogtreecommitdiff
path: root/include/std_gc/hash_map.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/std_gc/hash_map.h')
-rw-r--r--include/std_gc/hash_map.h33
1 files changed, 31 insertions, 2 deletions
diff --git a/include/std_gc/hash_map.h b/include/std_gc/hash_map.h
index e1a016d..fb6221b 100644
--- a/include/std_gc/hash_map.h
+++ b/include/std_gc/hash_map.h
@@ -2,15 +2,30 @@
#define TSL_HASH_MAP_H
#include "../forward_decl.h"
+#include "../value.h"
#include <stdint.h>
#include <stddef.h>
+typedef struct TslHashMapNode TslHashMapNode;
+struct TslHashMapNode {
+ uint64_t hash;
+ TslValue key;
+ TslValue value;
+ TslHashMapNode *next;
+};
+
/* TODO: Optimize small hash map by using the members of the struct instead of allocating on heap */
-typedef struct {
+struct TslHashMap {
void *buckets_data; /* value=TslHashMapNode */
size_t buckets_size;
size_t buckets_capacity;
-} TslHashMap;
+};
+
+typedef struct {
+ TslHashMap *hash_map;
+ size_t index;
+ TslHashMapNode *node;
+} TslHashMapIterator;
void tsl_hash_map_init(TslHashMap *self);
@@ -27,4 +42,18 @@ TslValue* tsl_hash_map_get(TslHashMap *self, const TslValue *key);
*/
TslValue* tsl_hash_map_get_or_create(TslHashMap *self, const TslValue *key);
+/*
+ How to use the iterator:
+
+ TslHashMapIterator iterator;
+ tsl_hash_map_create_iterator(hash_map, &iterator);
+ while(tsl_hash_map_iterator_next(&iterator)) {
+ TslValue *key = &iterator.node->key;
+ TslValue *value = &iterator.node->value;
+ }
+*/
+
+void tsl_hash_map_create_iterator(TslHashMap *self, TslHashMapIterator *iterator);
+int tsl_hash_map_iterator_next(TslHashMapIterator *self);
+
#endif /* TSL_HASH_MAP_H */