fix memory being freed too early

This commit is contained in:
William Bell
2025-08-10 04:39:50 +01:00
parent 49b1c1858a
commit c71375c7a4
12 changed files with 126 additions and 73 deletions

View File

@@ -15,7 +15,8 @@
struct hashmap_GC *createHashmap_GC() {
size_t size = 8;
struct hashmap_GC *t = (struct hashmap_GC *)ar_alloc(sizeof(struct hashmap_GC));
struct hashmap_GC *t =
(struct hashmap_GC *)ar_alloc(sizeof(struct hashmap_GC));
t->size = size;
t->order = 1;
t->list = (struct node_GC **)ar_alloc(sizeof(struct node_GC *) * size);
@@ -41,13 +42,15 @@ void resize_hashmap_GC(struct hashmap_GC *t) {
struct node_GC *temp = old_list[i];
while (temp) {
hashmap_insert_GC(t, temp->hash, temp->key, temp->val,
temp->order); // Will increment count
temp->order); // Will increment count
temp = temp->next;
}
}
}
int hashCode_GC(struct hashmap_GC *t, uint64_t hash) { return hash & (t->size - 1); }
int hashCode_GC(struct hashmap_GC *t, uint64_t hash) {
return hash & (t->size - 1);
}
int hashmap_remove_GC(struct hashmap_GC *t, uint64_t hash) {
int pos = hashCode_GC(t, hash);
@@ -72,7 +75,7 @@ int hashmap_remove_GC(struct hashmap_GC *t, uint64_t hash) {
}
void hashmap_insert_GC(struct hashmap_GC *t, uint64_t hash, void *key,
void *val, size_t order) {
void *val, size_t order) {
if (!order) {
order = t->order++;
}