Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions 05-methods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,27 @@ the new item at its location.
// hash_table.c
void ht_insert(ht_hash_table* ht, const char* key, const char* value) {
// ...
int del_index = -1;
while (cur_item != NULL) {
       if (cur_item != &HT_DELETED_ITEM) {
if (strcmp(cur_item->key, key) == 0) {
ht_del_item(cur_item);
ht->items[index] = item;
return;
}
} else if (del_index == -1) {
del_index = index;
}
// ...
index = ht_get_hash(item->key, ht->size, i);
cur_item = ht->items[index];
i++;
}
// ...
if (del_index != -1) {
ht->items[del_index] = item;
} else {
ht->items[index] = item;
}
ht->count++;
}
```

Expand Down