aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hashtable.c10
-rw-r--r--hashtable.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/hashtable.c b/hashtable.c
index ae32d38..0b4409f 100644
--- a/hashtable.c
+++ b/hashtable.c
@@ -58,12 +58,22 @@ void* list_get(list_node_t* head, const char* k) {
return (void*)0;
}
+size_t list_length(list_node_t* head) {
+ size_t length = 0;
+ while(head) {
+ length++;
+ head = head->next;
+ }
+ return length;
+}
+
hash_table_t* hashtable_new(size_t size) {
hash_table_t* ht = NULL;
if(size > 0) {
ht = (hash_table_t*)malloc(sizeof(hash_table_t));
ht->sz = size;
ht->t = (list_node_t**)malloc(sizeof(list_node_t*) * size);
+ for(int i = 0; i < size; i++) ht->t[i] = NULL;
}
return ht;
}
diff --git a/hashtable.h b/hashtable.h
index 1c3fea7..0baca4c 100644
--- a/hashtable.h
+++ b/hashtable.h
@@ -20,6 +20,7 @@ uint32_t hash_str(const char *s);
list_node_t* list_add(list_node_t* head, const char* k, void* v);
list_node_t* list_remove(list_node_t* head, const char* k);
void* list_get(list_node_t* head, const char* k);
+size_t list_length(list_node_t* head);
hash_table_t* hashtable_new(size_t size);
void hash_table_free(hash_table_t* ht);