From 08303f6a546cfb12ba59e37cda56daa91729b0df Mon Sep 17 00:00:00 2001 From: Daoctor Date: Wed, 30 Aug 2017 21:01:52 +0800 Subject: [PATCH] fix ht_del_hash_table function --- 05-methods/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/05-methods/README.md b/05-methods/README.md index fc74c08..f716f84 100644 --- a/05-methods/README.md +++ b/05-methods/README.md @@ -154,5 +154,19 @@ void ht_insert(ht_hash_table* ht, const char* key, const char* value) { } ``` +We also need to modify the `ht_del_hash_table` to skip the deleted item. +```c +void ht_del_hash_table(ht_hash_table* ht) { + for (int i = 0; i < ht->size; i++) { + ht_item* item = ht->items[i]; + if (item != NULL && item != &HT_DELETED_ITEM) { + ht_del_item(item); + } + } + free(ht->items); + free(ht); +} +``` + Next section: [Resizing tables](/06-resizing) [Table of contents](https://github.com/jamesroutley/write-a-hash-table#contents)