Enlightenment CVS committal Author : englebass Project : e17 Module : libs/ecore
Dir : e17/libs/ecore/src/lib/ecore Modified Files: Ecore_Data.h ecore_hash.c Log Message: Add a function to find a value in a hash. =================================================================== RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/Ecore_Data.h,v retrieving revision 1.40 retrieving revision 1.41 diff -u -3 -r1.40 -r1.41 --- Ecore_Data.h 15 Mar 2007 22:21:26 -0000 1.40 +++ Ecore_Data.h 25 Mar 2007 16:44:11 -0000 1.41 @@ -277,6 +277,7 @@ 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); =================================================================== RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/ecore_hash.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -3 -r1.34 -r1.35 --- ecore_hash.c 17 Jan 2007 13:41:08 -0000 1.34 +++ ecore_hash.c 25 Mar 2007 16:44:11 -0000 1.35 @@ -537,6 +537,40 @@ 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 ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs