From: Pekka Riikonen Date: Wed, 9 Oct 2002 16:52:10 +0000 (+0000) Subject: silc_hash_table_find_foreach calls once the callback also if X-Git-Tag: silc.client.0.9.6~44 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=99841a014bb70fad55174fc89e2c531c4e248e41 silc_hash_table_find_foreach calls once the callback also if the nothing was found (context is set to NULL) --- diff --git a/lib/silcutil/silchashtable.c b/lib/silcutil/silchashtable.c index 84549ad8..eb3b180e 100644 --- a/lib/silcutil/silchashtable.c +++ b/lib/silcutil/silchashtable.c @@ -215,7 +215,7 @@ silc_hash_table_find_internal_all(SilcHashTable ht, void *key, void *foreach_user_context) { SilcHashTableEntry *entry, *tmp; - bool auto_rehash; + bool auto_rehash, found = FALSE; SilcUInt32 i = SILC_HASH_TABLE_HASH(hash, hash_user_context); SILC_HT_DEBUG(("index %d key %p", i, key)); @@ -231,6 +231,7 @@ silc_hash_table_find_internal_all(SilcHashTable ht, void *key, if (compare((*entry)->key, key, compare_user_context)) { tmp = &(*entry)->next; foreach((*entry)->key, (*entry)->context, foreach_user_context); + found = TRUE; entry = tmp; continue; } @@ -241,6 +242,7 @@ silc_hash_table_find_internal_all(SilcHashTable ht, void *key, if ((*entry)->key == key) { tmp = &(*entry)->next; foreach((*entry)->key, (*entry)->context, foreach_user_context); + found = TRUE; entry = tmp; continue; } @@ -248,6 +250,10 @@ silc_hash_table_find_internal_all(SilcHashTable ht, void *key, } } + /* If nothing was found call with NULL context the callback */ + if (!found) + foreach(key, NULL, foreach_user_context); + ht->auto_rehash = auto_rehash; } diff --git a/lib/silcutil/silchashtable.h b/lib/silcutil/silchashtable.h index 22888777..690eff47 100644 --- a/lib/silcutil/silchashtable.h +++ b/lib/silcutil/silchashtable.h @@ -358,7 +358,9 @@ bool silc_hash_table_find_by_context(SilcHashTable ht, void *key, * As the hash table is collision resistant it is possible to save duplicate * keys to the hash table. This function can be used to find all keys * and contexts from the hash table that are found using the `key'. The - * `foreach' is called for every found key. + * `foreach' is called for every found key. If no entries can be found + * the `foreach' will be called once with the context set NULL and + * `key' and `user_context' sent to the function. * * NOTES * @@ -630,7 +632,9 @@ bool silc_hash_table_find_ext(SilcHashTable ht, void *key, * As the hash table is collision resistant it is possible to save duplicate * keys to the hash table. This function can be used to find all keys * and contexts from the hash table that are found using the `key'. The - * `foreach' is called for every found key. + * `foreach' is called for every found key. If no entries can be found + * the `foreach' will be called once with the context set NULL and + * `key' and `user_context' sent to the function. * * The `hash' and `hash_user_context' are application specified hash * function. If not provided the hash table's default is used.