Re: GHashTable ( Missing something ?) (Found what was missing)
- From: Harring Figueiredo <harringf yahoo com>
- To: Harring Figueiredo <harringf yahoo com>, gtk-app-devel-list gnome org
- Cc:
- Subject: Re: GHashTable ( Missing something ?) (Found what was missing)
- Date: Fri, 24 Sep 2004 14:48:13 -0700 (PDT)
The g_hash_table_insert resues the key - I was deleting it.
The source code says that the key is "reused"..
from ghash.c
297 /* do not reset node->key in this place, keeping
298 * the old key is the intended behaviour.
299 * g_hash_table_replace() can be used instead.
300 */
301
302 /* free the passed key */
303 if (hash_table->key_destroy_func)
The docs says:"
If the key already exists in the GHashTable its current value is replaced with
the new value.
Perhaps I should file a doc. bug ?
Thanks,
Harring.
--- Harring Figueiredo <harringf yahoo com> wrote:
Folks, I am doing a lookup on a hastable, and it always returns NULL, even
though the key exist -- (Now, I know it's is friday, but I have not started
drinking yet :P) -- Note that the GEqualFunc is never called.
---- <code> --------------------
gboolean my_str_compare(char* k, char* k2){
fprintf(stderr,"Comparing k=[%s] with k2=[%s]\n", k, k2);
//return g_str_equal((gpointer)k,(gpointer)k2);
return strcmp(k,k2) == 0;
}
void dump(gpointer pkey, gpointer entry, gpointer _null)
{
CfgEntry* e = (CfgEntry*) entry;
fprintf(stderr, "DUMP key(p)=%s, val=%s, d=%s\n", (char*)pkey, e->val,
e->desc);
fprintf(stderr, "DUMP key=%s, val=%s, d=%s\n", e->key, e->val, e->desc);
}
CfgEntry* cfg_get_entry(const char* key){
g_return_val_if_fail(key != NULL, NULL);
fprintf(stderr, "Looking for passed in key: %s\n", key);
g_hash_table_foreach(table, dump, NULL);
return g_hash_table_lookup(table, key);
}
My Hastable is created with:
g_hash_table_netable = g_hash_table_new_full(g_str_hash,
(GEqualFunc)my_str_compare, NULL, (GDestroyNotify)cfg_entry_unref );
--------------- </code> -----------------------
----------- <output> ---------------
Looking for passed in key: My_key
DUMP key(p)=MY_key, val=value for the key, d=#description for this entry
DUMP key=MY_key, val=value for the key, d=#description for this entry
Did not find entry for key
-------------- </output>----------------------
NOTE that the my_str_compare is never called.
What the heck am I missing here ?
Perhaps I need a break from the keyboard..
Thanks for any help.
Harring
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]