Re: API for iterating the g_hash_table



On 14 Jan 2004, Sven Neumann wrote:

> Hi,
> 
> dhaude physnet uni-hamburg de writes:
> 
> > It is rather trivial to construct a GList of hash table keys (or
> > values) using g_hash_table_foreach. Of course it's only useful on
> > a table whose contents change never or seldom because the list
> > has to be updated on each change. Anyway, here's what I use. I
> > was too lazy to make Append_key() the right type.
> > 
> > void append_key(void *k, void *v, GList **keys)
> > {
> > }
> > 
> > GList *get_hash_keys(GHashTable *hash)
> > {
> >         GList *keys = NULL;
> >         
> >         g_hash_table_foreach(hash, append_key, &keys);
> >         return keys;
> > }
> 
> Let's hope your implementation of append_key() uses g_list_prepend()
> or this code will be horribly inefficient for large hash tables.

Indeed I use append_key (somehow the function body of append_key
went missing):


	*keys = g_list_append(*keys, k);

Of course you're right, thanks for pointing it out. 

--Daniel




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