diff options
author | mescalinum <mescalinum@users.sourceforge.net> | 2011-10-15 15:52:29 +0000 |
---|---|---|
committer | mescalinum <mescalinum@users.sourceforge.net> | 2011-10-15 15:52:29 +0000 |
commit | 5d7b51638d572ab41557c5a80ebff69d9320e740 (patch) | |
tree | b410b6f83981de7eb4000a295661f089018d02fd | |
parent | f7dd0d906c42c7f0e0e5d5fecc8d987b35901d75 (diff) |
add list length
svn path=/trunk/externals/loaders/tclpd/; revision=15604
-rw-r--r-- | hashtable.c | 10 | ||||
-rw-r--r-- | hashtable.h | 1 |
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);
|