aboutsummaryrefslogtreecommitdiff
path: root/src/hashtable.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/hashtable.h')
-rw-r--r--src/hashtable.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/hashtable.h b/src/hashtable.h
index 42d0166..8f73066 100644
--- a/src/hashtable.h
+++ b/src/hashtable.h
@@ -33,7 +33,9 @@ void *table_reset(struct table *table, int *count);
#include <stdlib.h>
#include <string.h>
-static struct bucket *
+#define internal static
+
+internal struct bucket *
table_new_bucket(void *key, void *value)
{
struct bucket *bucket = malloc(sizeof(struct bucket));
@@ -43,7 +45,7 @@ table_new_bucket(void *key, void *value)
return bucket;
}
-static struct bucket **
+internal struct bucket **
table_get_bucket(struct table *table, void *key)
{
struct bucket **bucket = table->buckets + (table->hash(key) % table->capacity);
@@ -56,6 +58,8 @@ table_get_bucket(struct table *table, void *key)
return bucket;
}
+#undef internal
+
void table_init(struct table *table, int capacity, table_hash_func hash, table_compare_func compare)
{
table->count = 0;
@@ -76,7 +80,10 @@ void table_free(struct table *table)
bucket = next;
}
}
- free(table->buckets);
+ if (table->buckets) {
+ free(table->buckets);
+ table->buckets = NULL;
+ }
}
void *table_find(struct table *table, void *key)