Re: API for iterating the g_hash_table

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

 



Hi,

Tony Yat-Tung Cheung <dragonman@xxxxxxxxxxxx> writes:

> 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;
> }

This looks rather akward since it exposes internals like the position
of an element in the hash table. If this functionality is actually
needed (do you have a use case?), then it should be an extended
version of g_hash_table_foreach() that stops traversal when the
callback function returns TRUE (just like g_tree_foreach).


Sven
_______________________________________________

gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux