fix: Fixes in hasntable
This commit is contained in:
+9
-5
@@ -99,7 +99,7 @@ void *hashtable_set(hashtable h, const char *key, void *value)
|
||||
}
|
||||
// found replace the value
|
||||
void *old_value = item.found->value;
|
||||
item.found-> value = value;
|
||||
item.found->value = value;
|
||||
|
||||
return old_value;
|
||||
}
|
||||
@@ -137,19 +137,20 @@ void hashtable_destroy_bucket(hashtable h, int i)
|
||||
{
|
||||
struct entry *e = h->table[i];
|
||||
while (e != NULL) {
|
||||
struct entry *next = e->next;
|
||||
free((void*)e->key);
|
||||
e = e->next;
|
||||
free(e);
|
||||
e = next;
|
||||
}
|
||||
}
|
||||
|
||||
void hashtable_destroy(hashtable h)
|
||||
{
|
||||
if (h==NULL) return;
|
||||
if (h == NULL) return;
|
||||
for (int i = 0; i < h->size; i++) {
|
||||
hashtable_destroy_bucket(h, i);
|
||||
}
|
||||
free (h->table);
|
||||
free(h->table);
|
||||
free(h);
|
||||
}
|
||||
|
||||
@@ -171,12 +172,15 @@ bool ht_iter_next(ht_iterator *iter)
|
||||
}
|
||||
hashtable h = iter->h;
|
||||
|
||||
while(true) {
|
||||
while (true) {
|
||||
if (iter->index >= h->size) {
|
||||
return false;
|
||||
}
|
||||
if (iter->entry == NULL) {
|
||||
iter->index++;
|
||||
if (iter->index >= h->size) {
|
||||
return false;
|
||||
}
|
||||
iter->entry = h->table[iter->index];
|
||||
} else {
|
||||
iter->entry = iter->entry->next;
|
||||
|
||||
Reference in New Issue
Block a user