start working on runtime
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
#include "hashmap.h"
|
||||
|
||||
#include <gc/gc.h>
|
||||
#include <stdlib.h>
|
||||
#include "../memory.h"
|
||||
|
||||
struct table *createTable(int size)
|
||||
{
|
||||
struct table *t = (struct table *)checked_malloc(sizeof(struct table));
|
||||
struct table *t = (struct table *)ar_alloc(sizeof(struct table));
|
||||
t->size = size;
|
||||
t->list = (struct node **)checked_malloc(sizeof(struct node *) * size);
|
||||
t->list = (struct node **)ar_alloc(sizeof(struct node *) * size);
|
||||
int i;
|
||||
for (i = 0; i < size; i++)
|
||||
t->list[i] = NULL;
|
||||
@@ -49,7 +50,7 @@ void insert(struct table *t, int key, void* val)
|
||||
{
|
||||
int pos = hashCode(t, key);
|
||||
struct node *list = t->list[pos];
|
||||
struct node *newNode = (struct node *)checked_malloc(sizeof(struct node));
|
||||
struct node *newNode = (struct node *)ar_alloc(sizeof(struct node));
|
||||
struct node *temp = list;
|
||||
while (temp)
|
||||
{
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
#ifndef HASHMAP_H
|
||||
#define HASHMAP_H
|
||||
#include <stdlib.h>
|
||||
|
||||
struct node
|
||||
{
|
||||
int key;
|
||||
size_t key;
|
||||
void *val;
|
||||
struct node *next;
|
||||
};
|
||||
struct table
|
||||
{
|
||||
int size;
|
||||
size_t size;
|
||||
size_t count;
|
||||
struct node **list;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user