GHashTable Question
- From: jseymour LinxNet com (Jim Seymour)
- To: gtk-app-devel-list gnome org
- Subject: GHashTable Question
- Date: Thu, 25 Apr 2002 19:31:49 -0400 (EDT)
In a tutorial kinda thing at
http://www.ximian.com/devzone/tutorials/self-help-1.html#know
The author states that "...when a duplicate node is inserted into a
hash table it is the old key is retained, and the new key is not
inserted."
Yet the GLib docs (both 1.2 and 2.x) say:
"If the key already exists in the GHashTable its current value
is replaced with the new value."
Thus it seems to *me* that the following code snippit is correct:
gpointer val = g_hash_table_lookup(jd->hash, name);
.
.
.
if (val) {
g_free(val);
g_hash_table_insert(jd->hash, name, msg);
} else {
g_hash_table_insert(jd->hash, g_strdup(name), msg);
}
Where: "name" is the key and "msg" (a string in alloc'd memory) is the
value.
Are the Ximian docs correct and the API docs wrong?
Thanks,
Jim
--
Jim Seymour | PGP Public Key available at:
jseymour LinxNet com | http://www.uk.pgp.net/pgpnet/pks-commands.html
http://jimsun.LinxNet.com |
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]