GTree stuff
- From: Simon K}gedal <sika8225 csd uu se>
- To: gtk-devel-list redhat com
- Subject: GTree stuff
- Date: Thu, 26 Nov 1998 18:50:57 +0100
Hi.
I need to create some kind of lookup table gint -> MyType *.
Now, what feels most natural for me is to use a binary search
tree like GTree is. I want to be able to traverse that GTree,
for freeing all my MyType * and other things. But my tree
also might be unpopulated.
g_tree_traverse doesn't like this. I wonder why and propose
this patch:
--8<------------------------------------------------------------------
--- gtree.c.Orig Mon Nov 23 21:37:55 1998
+++ gtree.c Mon Nov 23 21:40:54 1998
@@ -164,7 +164,8 @@
rtree = (GRealTree*) tree;
- g_return_if_fail (rtree->root != NULL);
+ if (!rtree->root)
+ return;
switch (traverse_type)
{
--8<------------------------------------------------------------------
It would also be nice with a function to check if a given tree
is empty, since g_tree_nnodes is unneccessary expensive if all you want
to know is if it's empty. Something like this (somewhere in gtree.c):
gboolean
g_tree_is_empty (GTree *tree)
{
GRealTree *rtree;
rtree = (GRealTree*) tree;
return (rtree->root == NULL);
}
(hmmm I had to improvise now but if this is wrong i really suck :) )
Thanks,
--
Simon Kågedal <simon@sdf.se> - Homepage: http://www.sdf.se/~simon/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]