Added Hash map marking

This commit is contained in:
valtermiari 2023-05-04 13:51:53 +02:00 committed by Victor Olin
parent 3e188553d6
commit a5c5d122b2
8 changed files with 133 additions and 28 deletions

View file

@ -12,17 +12,7 @@ typedef struct node {
Node *HEAD = NULL;
Node *CURRENT = NULL;
// Creates a linked list of length depth. Global head "HEAD" is updated.
void *create_linked_list(int depth) {
HEAD = (Node*)(cheap_alloc(sizeof(Node)));
HEAD->id = 0;
// Purposely omitting adding a child to "last_node", since its the last node
for (int i = 1; i < depth - 1; i++) {
insert_first(i);
}
}
void *insert_first(int node_id) {
void insert_first(int node_id) {
Node *new_head;
new_head = (Node*)(cheap_alloc(sizeof(Node)));
new_head->id = node_id;
@ -31,15 +21,33 @@ void *insert_first(int node_id) {
HEAD = new_head;
}
void test_linked_list(int list_length){
// Creates a linked list of length depth. Global head "HEAD" is updated.
Node *create_linked_list(int depth) {
HEAD = (Node*)(cheap_alloc(sizeof(Node)));
HEAD->id = 0;
// Purposely omitting adding a child to "last_node", since its the last node
for (int i = 1; i < depth - 1; i++) {
insert_first(i);
}
return HEAD;
}
void create_garbage(int amount) {
for (int i = 0; i < amount; i++) {
long *garbage = (long*)(cheap_alloc(sizeof(long)));
}
}
int main () {
cheap_init();
cheap_t *heap = cheap_the();
cheap_set_profiler(heap, true);
create_linked_list(list_length);
cheap_dispose();
free(heap);
}
int main (int argc, char **argv) {
test_linked_list(30);
// Every node in this list should be marked
Node *head = create_linked_list(5);
// Everything create here should be swept
create_garbage(30);
cheap_dispose();
return 0;
}