test uc_htable_clear. Add comments, fix uc_htable_next
This commit is contained in:
+10
-2
@@ -39,6 +39,7 @@ struct UHNode *uc_htable_first_hash(const struct UHTable *table, size_t hash)
|
||||
return it;
|
||||
}
|
||||
|
||||
//given a node, find the next one in the chain with the given hash
|
||||
struct UHNode *uc_htable_next_hash_hlp(struct UHNode *next, size_t hash)
|
||||
{
|
||||
while (next && next->hash != hash) {
|
||||
@@ -48,11 +49,13 @@ struct UHNode *uc_htable_next_hash_hlp(struct UHNode *next, size_t hash)
|
||||
return next;
|
||||
}
|
||||
|
||||
struct UHNode *uc_htable_next_hlp(struct UHTable *table, size_t bucket)
|
||||
//find a node, starting at bucket
|
||||
struct UHNode *uc_htable_iter_hlp(struct UHTable *table, size_t bucket)
|
||||
{
|
||||
size_t i;
|
||||
struct UHNode *found = NULL;
|
||||
|
||||
//search through buckets until a node is found
|
||||
for (i = bucket; i < table->cnt_buckets; i++) {
|
||||
found = uc_htable_first_bucket(table, i);
|
||||
if (found != NULL) {
|
||||
@@ -68,7 +71,8 @@ struct UHNode *uc_htable_next(struct UHTable *table, struct UHNode *node)
|
||||
|
||||
found = uc_htable_next_bucket(node);
|
||||
if (found == NULL) {
|
||||
found = uc_htable_next_hlp(table, node->hash + 1);
|
||||
size_t current_bucket = uc_htable_bucket(table, node->hash);
|
||||
found = uc_htable_iter_hlp(table, current_bucket + 1);
|
||||
}
|
||||
|
||||
return found;
|
||||
@@ -139,11 +143,14 @@ int uc_htable_resize(struct UHTable *table, size_t buckets)
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
//create new temp table
|
||||
rc = uc_htable_init(&tmp_table, buckets);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
//move all the nodes to the new temp table
|
||||
for (h = 0; h < table->cnt_buckets; h++) {
|
||||
struct UHNode *next;
|
||||
struct UHNode *node;
|
||||
@@ -156,6 +163,7 @@ int uc_htable_resize(struct UHTable *table, size_t buckets)
|
||||
}
|
||||
}
|
||||
|
||||
//replace the existing table with the resized temp table
|
||||
uc_htable_swap(&tmp_table, table);
|
||||
uc_htable_destroy(&tmp_table);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user