Re: g_hash_table_get_keys()/g_hash_table_get_values()



Havoc Pennington <hp@redhat.com> writes:

> I fairly frequently do a g_hash_table_foreach() for the sole purpose
> of getting a list of keys or values from a hash table. Python has
> methods hash.keys() and hash.values() that return a list of keys or
> values.
> 
> So, proposal for something I think would be nice:
> 
>  GSList* g_hash_table_get_keys   (GHashTable *table);
>  GSList* g_hash_table_get_values (GHashTable *table);
> 
> The returned list must be freed.

I think this is gratuitous sugar.

Sometimes you want a GSList, sometimes a GList, sometimes an array;
sometimes you want to stash things in a tree.  And most of the time
you want both the key and the value, not just one of them.

I think the foreach() is fine.

  Federico




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