aboutsummaryrefslogtreecommitdiff
path: root/src/std_gc
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-01-26 08:02:17 +0100
committerdec05eba <dec05eba@protonmail.com>2020-01-26 08:03:53 +0100
commit31519e8a586791d60e6e56e558c2a3bf973cc1f9 (patch)
tree9195b99953568103fe58025d5888960a48a0c051 /src/std_gc
parent5df950e0b35207930c645e8ce0c3e9ed1c9fcea5 (diff)
Implement plus operator and indexing of strings
Diffstat (limited to 'src/std_gc')
-rw-r--r--src/std_gc/hash_map.c37
-rw-r--r--src/std_gc/list.c2
2 files changed, 29 insertions, 10 deletions
diff --git a/src/std_gc/hash_map.c b/src/std_gc/hash_map.c
index 4d4c026..3f12f35 100644
--- a/src/std_gc/hash_map.c
+++ b/src/std_gc/hash_map.c
@@ -1,18 +1,9 @@
#include "../../include/std_gc/hash_map.h"
-#include "../../include/value.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <gc.h>
-typedef struct TslHashMapNode TslHashMapNode;
-struct TslHashMapNode {
- uint64_t hash;
- TslValue key;
- TslValue value;
- TslHashMapNode *next;
-};
-
void tsl_hash_map_init(TslHashMap *self) {
self->buckets_data = NULL;
self->buckets_size = 0;
@@ -193,3 +184,31 @@ TslValue* tsl_hash_map_get_or_create(TslHashMap *self, const TslValue *key) {
return value;
}
+
+void tsl_hash_map_create_iterator(TslHashMap *self, TslHashMapIterator *iterator) {
+ iterator->hash_map = self;
+ iterator->index = -1;
+ iterator->node = NULL;
+}
+
+int tsl_hash_map_iterator_next(TslHashMapIterator *self) {
+ if(self->node) {
+ TslHashMapNode *new_node = self->node->next;
+ if(new_node) {
+ self->node = new_node;
+ return 1;
+ }
+ }
+
+ ++self->index;
+ while(self->index < self->hash_map->buckets_size) {
+ TslHashMapNode **bucket = (TslHashMapNode**)self->hash_map->buckets_data + self->index;
+ if(*bucket) {
+ self->node = *bucket;
+ return 1;
+ }
+ ++self->index;
+ }
+
+ return 0;
+}
diff --git a/src/std_gc/list.c b/src/std_gc/list.c
index 5b7c7b6..7c56d64 100644
--- a/src/std_gc/list.c
+++ b/src/std_gc/list.c
@@ -58,7 +58,7 @@ TslValue* tsl_list_end(TslList *self) {
return (TslValue*)((char*)self->data + self->size);
}
-TslValue* tsl_list_get(TslList *self, double index) {
+TslValue* tsl_list_get(const TslList *self, double index) {
/* TODO: Verify if overflow check is needed */
intptr_t index_i = index;
if(index_i >= 0 && index_i < (intptr_t)self->size / (intptr_t)sizeof(TslValue))