API for iterating the g_hash_table



Hi,

Is there any API for iterating GHashTable?

I only see the the g_hash_table_foreach() here. But sometimes people may like to iterate through a hash table and stop the iteration when certain conditions are met.

Currently, there is g_hash_table_size(), we could easily add iteration by providing the following two new APIs,

gconstpointer g_hash_table_get_key(GHashTable *hash_table, int pos);
gconspointer g_hash_table_get_value(GHashTable *hash_table, int pos);

The two APIs allows one to iterate the hash table, for example,

for (i = 0; i < g_hash_table_size(hash_table); i++) {
 gconstpointer value = g_hash_table_get_value(hash_table, i);

 /* Do some processing here */
 if (is_match(value))
   return TRUE;
}

Should we add the APIs?

Regards,
Tony Cheung



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]