[dovecot-cvs] dovecot/src/lib hash.c,1.21,1.22 hash.h,1.11,1.12
cras at dovecot.org
cras at dovecot.org
Sun Sep 25 13:35:19 EEST 2005
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv7874
Modified Files:
hash.c hash.h
Log Message:
Added hash_copy() and added some consts
Index: hash.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/hash.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- hash.c 3 Dec 2003 18:14:26 -0000 1.21
+++ hash.c 25 Sep 2005 10:35:17 -0000 1.22
@@ -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)
{
Index: hash.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/hash.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- hash.h 3 Dec 2003 00:40:21 -0000 1.11
+++ hash.h 25 Sep 2005 10:35:17 -0000 1.12
@@ -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);
More information about the dovecot-cvs
mailing list