aboutsummaryrefslogtreecommitdiff
path: root/include/std_gc
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-01-24 09:11:53 +0100
committerdec05eba <dec05eba@protonmail.com>2020-01-24 09:11:53 +0100
commit1dd53ce54c2008e3a11a636a496853cf6f9a5d65 (patch)
tree73f8ff8d048c8b1e4c6cf7acfd3e229650d044d5 /include/std_gc
parent26f8fbc2c657ecffc874410691dd3fc83ba11131 (diff)
Convert hash map to gc, implement more instructions and call command
Diffstat (limited to 'include/std_gc')
-rw-r--r--include/std_gc/hash_map.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/include/std_gc/hash_map.h b/include/std_gc/hash_map.h
new file mode 100644
index 0000000..e67dd75
--- /dev/null
+++ b/include/std_gc/hash_map.h
@@ -0,0 +1,29 @@
+#ifndef TSL_HASH_MAP_H
+#define TSL_HASH_MAP_H
+
+#include "../value.h"
+#include <stdint.h>
+
+/* TODO: Optimize small hash map by using the members of the struct instead of allocating on heap */
+typedef struct {
+ void *buckets_data; /* value=TslHashMapNode */
+ size_t buckets_size;
+ size_t buckets_capacity;
+} TslHashMap;
+
+void tsl_hash_map_init(TslHashMap *self);
+
+int tsl_hash_map_insert(TslHashMap *self, const TslValue *key, TslValue *value);
+/*
+ Get a reference to the value by key @key, or NULL if it doesn't exist.
+ The returned pointer is only valid until until reallocation after after insert inserting a new value into the hash map.
+*/
+TslValue* tsl_hash_map_get(TslHashMap *self, const TslValue *key);
+/*
+ Get a reference to the value by key @key, or insert a new value for the key (a TslValue).
+ Returns NULL on failure.
+ The returned pointer is only valid until until reallocation after after insert inserting a new value into the hash map.
+*/
+TslValue* tsl_hash_map_get_or_create(TslHashMap *self, const TslValue *key);
+
+#endif /* TSL_HASH_MAP_H */