rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit 1199cff0100ceb774f1ebd1f57985d6648b29cd6
parent fb12566597cf3b00535a4a9e679157e1a932a35a
Author: vaplv <vaplv@free.fr>
Date:   Thu, 22 Dec 2016 16:41:51 +0100

Add the hash table purge function

Diffstat:
Msrc/hash_table.h | 12++++++++++++
Msrc/test_hash_table.c | 10+++++++++-
2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/hash_table.h b/src/hash_table.h @@ -320,6 +320,18 @@ HTABLE_FUNC__(release)(struct HTABLE__* htbl) darray_char_release(&htbl->table_slot_is_used); } +/* Clean up the hash table and, unlike the clear function, ensure that the + * memory used to store the data is effectively released */ +static INLINE void +HTABLE_FUNC__(purge)(struct HTABLE__* htbl) +{ + struct mem_allocator* allocator; + ASSERT(htbl); + allocator = htbl->allocator; + HTABLE_FUNC__(release)(htbl); + HTABLE_FUNC__(init)(allocator, htbl); +} + static res_T HTABLE_FUNC__(reserve)(struct HTABLE__* htbl, const size_t size_submitted) { diff --git a/src/test_hash_table.c b/src/test_hash_table.c @@ -229,7 +229,7 @@ test_htbl_str_int(void) CHECK(str_found[i], 1); } - htable_str_int_clear(&htbl); + htable_str_int_purge(&htbl); htable_str_int_begin(&htbl, &it0); htable_str_int_end(&htbl, &it1); CHECK(htable_str_int_iterator_eq(&it0, &it1), 1); @@ -258,6 +258,14 @@ test_htbl_str_int(void) data = htable_str_int_find(&htbl, &tmp); NCHECK(data, NULL); CHECK(*data, 'a'); + + htable_str_int_clear(&htbl); + htable_str_int_begin(&htbl, &it0); + htable_str_int_end(&htbl, &it1); + CHECK(htable_str_int_iterator_eq(&it0, &it1), 1); + CHECK(htable_str_int_is_empty(&htbl), 1); + CHECK(htable_str_int_size_get(&htbl), 0); + htable_str_int_release(&htbl); str_release(&tmp);