[dovecot-cvs] dovecot/src/lib hash.c,1.11,1.12 hash.h,1.7,1.8
cras at procontrol.fi
cras at procontrol.fi
Sat Jan 11 19:42:57 EET 2003
Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv11548/lib
Modified Files:
hash.c hash.h
Log Message:
hash_clear() can now be used to drop the memory allocated using node_pool.
Index: hash.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/hash.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- hash.c 11 Jan 2003 15:37:18 -0000 1.11
+++ hash.c 11 Jan 2003 17:42:55 -0000 1.12
@@ -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,13 +146,19 @@
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,
Index: hash.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/hash.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- hash.h 11 Jan 2003 15:29:46 -0000 1.7
+++ hash.h 11 Jan 2003 17:42:55 -0000 1.8
@@ -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,
More information about the dovecot-cvs
mailing list