silc_hash_table_find_foreach calls once the callback also if
authorPekka Riikonen <priikone@silcnet.org>
Wed, 9 Oct 2002 16:52:10 +0000 (16:52 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 9 Oct 2002 16:52:10 +0000 (16:52 +0000)
the nothing was found (context is set to NULL)

lib/silcutil/silchashtable.c
lib/silcutil/silchashtable.h

index 84549ad8add4fbe025937988d67e15f6c6780908..eb3b180e1141574cba37878e75f8aef9db7ef8aa 100644 (file)
@@ -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;
 }
 
index 228887775a990655d5a1c8dbfa0bd34a4eaeef8c..690eff478f872fccb8b1b55afa2ae88b96bae0a0 100644 (file)
@@ -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.