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));
if (compare((*entry)->key, key, compare_user_context)) {
tmp = &(*entry)->next;
foreach((*entry)->key, (*entry)->context, foreach_user_context);
+ found = TRUE;
entry = tmp;
continue;
}
if ((*entry)->key == key) {
tmp = &(*entry)->next;
foreach((*entry)->key, (*entry)->context, foreach_user_context);
+ found = TRUE;
entry = tmp;
continue;
}
}
}
+ /* If nothing was found call with NULL context the callback */
+ if (!found)
+ foreach(key, NULL, foreach_user_context);
+
ht->auto_rehash = auto_rehash;
}
* 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
*
* 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.