Re: API for iterating the g_hash_table
- From: Sven Neumann <sven gimp org>
- To: tony cheung asiayeah com
- Cc: gtk-list gnome org
- Subject: Re: API for iterating the g_hash_table
- Date: 14 Jan 2004 15:37:25 +0100
Hi,
Tony Yat-Tung Cheung <dragonman asiayeah com> 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]