Mercurial > dovecot > original-hg > dovecot-1.2
changeset 949:e601f13d95b1 HEAD
hash_clear() can now be used to drop the memory allocated using node_pool.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 11 Jan 2003 19:42:55 +0200 |
parents | 70083370cc84 |
children | ceb3ea5e1a2a |
files | src/lib/hash.c src/lib/hash.h |
diffstat | 2 files changed, 14 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/hash.c Sat Jan 11 17:48:01 2003 +0200 +++ b/src/lib/hash.c Sat Jan 11 19:42:55 2003 +0200 @@ -88,7 +88,7 @@ { struct hash_table *table; - table = p_new(node_pool, struct hash_table, 1); + table = p_new(table_pool, struct hash_table, 1); table->table_pool = table_pool; table->node_pool = node_pool; table->size = I_MAX(primes_closest(initial_size), @@ -146,14 +146,20 @@ p_free(table->table_pool, table->nodes); p_free(table->table_pool, table->collisions); - p_free(table->node_pool, table); + p_free(table->table_pool, table); } -void hash_clear(struct hash_table *table) +void hash_clear(struct hash_table *table, int free_collisions) { if (!table->node_pool->alloconly_pool) hash_destroy_collision_nodes(table); + if (free_collisions) { + if (!table->node_pool->alloconly_pool) + destroy_collision(table, table->free_cnodes); + table->free_cnodes = NULL; + } + memset(table->nodes, 0, sizeof(struct hash_node) * table->size); memset(table->collisions, 0, sizeof(struct collision_node) * table->collisions_size);
--- a/src/lib/hash.h Sat Jan 11 17:48:01 2003 +0200 +++ b/src/lib/hash.h Sat Jan 11 19:42:55 2003 +0200 @@ -18,7 +18,11 @@ size_t initial_size, HashFunc hash_func, HashCompareFunc key_compare_func); void hash_destroy(struct hash_table *table); -void hash_clear(struct hash_table *table); + +/* Remove all nodes from hash table. If free_collisions is TRUE, the + memory allocated from node_pool is freed, or discarded with + alloconly pools. */ +void hash_clear(struct hash_table *table, int free_collisions); void *hash_lookup(struct hash_table *table, const void *key); int hash_lookup_full(struct hash_table *table, const void *lookup_key,