X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilchashtable.c;h=84549ad8add4fbe025937988d67e15f6c6780908;hb=da3a876c26b6d697ee6446ad81a8edfff1828cab;hp=d7bca802f7cd99575a29cd98797433ce5ddeb5fc;hpb=346885ee9466a6f1d5ecc99a5401aa3043acf7c0;p=silc.git diff --git a/lib/silcutil/silchashtable.c b/lib/silcutil/silchashtable.c index d7bca802..84549ad8 100644 --- a/lib/silcutil/silchashtable.c +++ b/lib/silcutil/silchashtable.c @@ -136,7 +136,7 @@ silc_hash_table_find_internal(SilcHashTable ht, void *key, } /* Internal routine to find entry in the hash table by `key' and `context'. - Returns the previous entry (if exists) as well. */ + Returns the previous entry (if exists) as well to `prev_entry'. */ static inline SilcHashTableEntry * silc_hash_table_find_internal_context(SilcHashTable ht, void *key, @@ -170,7 +170,8 @@ silc_hash_table_find_internal_context(SilcHashTable ht, void *key, } } - *prev_entry = prev; + if (prev_entry) + *prev_entry = prev; return entry; } @@ -683,6 +684,27 @@ bool silc_hash_table_find_ext(SilcHashTable ht, void *key, return TRUE; } +/* Same as silc_hash_table_find but finds with specific context. */ + +bool silc_hash_table_find_by_context(SilcHashTable ht, void *key, + void *context, void **ret_key) +{ + SilcHashTableEntry *entry; + + entry = silc_hash_table_find_internal_context(ht, key, context, NULL, + ht->hash, + ht->hash_user_context, + ht->compare, + ht->compare_user_context); + if (!entry || !(*entry)) + return FALSE; + + if (ret_key) + *ret_key = (*entry)->key; + + return TRUE; +} + /* 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