g_tree_insert overwrites all data

Posted by pechenie on Stack Overflow See other posts from Stack Overflow or by pechenie
Published on 2010-03-23T05:50:08Z Indexed on 2010/03/23 5:53 UTC
Read the original article Hit count: 272

Filed under:
|
|

I wonder how I should use the GTree (from GLib) to store data? Every new value I insert into GTree with g_tree_insert routine is overwrite the previous one!

GTree *tree; //init
tree = g_tree_new( g_str_equal ); //"g_str_equal" is a GLib default compare func
//...
for( i = 0; i < 100; ++i )
    g_tree_insert( tree, random_key(), random_value() ); //insert some random vals
//
printf( "%d", g_tree_nnodes( tree ) ); //should be 100? NO! Prints "1"!!!

What am I doing wrong? Thank you.

© Stack Overflow or respective owner

Related posts about bst

Related posts about binary-trees