Add a function to find a value in a hash.
SVN revision: 29129
This commit is contained in:
parent
c97009d447
commit
07cedee486
|
@ -277,6 +277,7 @@ extern "C" {
|
|||
EAPI int ecore_hash_set(Ecore_Hash *hash, void *key, void *value);
|
||||
EAPI int ecore_hash_set_hash(Ecore_Hash *hash, Ecore_Hash *set);
|
||||
EAPI void *ecore_hash_remove(Ecore_Hash *hash, const void *key);
|
||||
EAPI void *ecore_hash_find(Ecore_Hash *hash, Ecore_Compare_Cb compare, const void *value);
|
||||
EAPI void ecore_hash_dump_graph(Ecore_Hash *hash);
|
||||
EAPI void ecore_hash_dump_stats(Ecore_Hash *hash);
|
||||
|
||||
|
|
|
@ -537,6 +537,40 @@ ecore_hash_remove(Ecore_Hash *hash, const void *key)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the first value that matches
|
||||
* table.
|
||||
* @param hash The given hash table.
|
||||
* @param key The key to search for.
|
||||
* @return The value corresponding to key on success, @c NULL otherwise.
|
||||
* @ingroup Ecore_Data_Hash_ADT_Data_Group
|
||||
*/
|
||||
EAPI void *
|
||||
ecore_hash_find(Ecore_Hash *hash, Ecore_Compare_Cb compare, const void *value)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
|
||||
CHECK_PARAM_POINTER_RETURN("hash", hash, NULL);
|
||||
CHECK_PARAM_POINTER_RETURN("compare", compare, NULL);
|
||||
CHECK_PARAM_POINTER_RETURN("value", value, NULL);
|
||||
|
||||
while (i < ecore_prime_table[hash->size])
|
||||
{
|
||||
if (hash->buckets[i])
|
||||
{
|
||||
Ecore_Hash_Node *node;
|
||||
|
||||
for (node = hash->buckets[i]; node; node = node->next)
|
||||
{
|
||||
if (!compare(node->value, value)) return node->value;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief Retrieve the node associated with key
|
||||
* @param hash: the hash table to search for the key
|
||||
|
|
Loading…
Reference in New Issue