Mercurial > dovecot > original-hg > dovecot-1.2
changeset 3616:906b87e236bf HEAD
Added hash_copy() and added some consts
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 25 Sep 2005 13:35:17 +0300 |
parents | 0a885029543b |
children | 904849549eac |
files | src/lib/hash.c src/lib/hash.h |
diffstat | 2 files changed, 26 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/hash.c Sun Sep 25 13:24:09 2005 +0300 +++ b/src/lib/hash.c Sun Sep 25 13:35:17 2005 +0300 @@ -132,7 +132,8 @@ } static struct hash_node * -hash_lookup_node(struct hash_table *table, const void *key, unsigned int hash) +hash_lookup_node(const struct hash_table *table, + const void *key, unsigned int hash) { struct hash_node *node; @@ -149,7 +150,7 @@ return NULL; } -void *hash_lookup(struct hash_table *table, const void *key) +void *hash_lookup(const struct hash_table *table, const void *key) { struct hash_node *node; @@ -157,7 +158,7 @@ return node != NULL ? node->value : NULL; } -int hash_lookup_full(struct hash_table *table, const void *lookup_key, +int hash_lookup_full(const struct hash_table *table, const void *lookup_key, void **orig_key, void **value) { struct hash_node *node; @@ -320,7 +321,7 @@ hash_compress(table, &table->nodes[hash % table->size]); } -size_t hash_size(struct hash_table *table) +size_t hash_size(const struct hash_table *table) { return table->nodes_count; } @@ -450,6 +451,21 @@ return TRUE; } +void hash_copy(struct hash_table *dest, struct hash_table *src) +{ + struct hash_iterate_context *iter; + void *key, *value; + + hash_freeze(dest); + + iter = hash_iterate_init(src); + while (hash_iterate(iter, &key, &value)) + hash_insert(dest, key, value); + hash_iterate_deinit(iter); + + hash_thaw(dest); +} + /* a char* hash function from ASU -- from glib */ unsigned int str_hash(const void *p) {
--- a/src/lib/hash.h Sun Sep 25 13:24:09 2005 +0300 +++ b/src/lib/hash.h Sun Sep 25 13:35:17 2005 +0300 @@ -22,8 +22,8 @@ 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, +void *hash_lookup(const struct hash_table *table, const void *key); +int hash_lookup_full(const struct hash_table *table, const void *lookup_key, void **orig_key, void **value); /* Insert/update node in hash table. The difference is that hash_insert() @@ -32,7 +32,7 @@ void hash_update(struct hash_table *table, void *key, void *value); void hash_remove(struct hash_table *table, const void *key); -size_t hash_size(struct hash_table *table); +size_t hash_size(const struct hash_table *table); /* Iterates through all nodes in hash table. You may safely call hash_*() functions while iterating, but if you add any new nodes, they may or may @@ -47,6 +47,9 @@ void hash_freeze(struct hash_table *table); void hash_thaw(struct hash_table *table); +/* Copy all nodes from one hash table to another */ +void hash_copy(struct hash_table *dest, struct hash_table *src); + /* hash function for strings */ unsigned int str_hash(const void *p); unsigned int strcase_hash(const void *p);