Re: Three more functions for GTree



On Tue, 16 May 2000, Svanberg Liss wrote:

> Hello!
> Is there any interest to include these extensions to GTree in glib-1.3?
> 
> void g_tree_traverse_interval( GTree*, GTraverseFunc, GTraverseType,
> gconstpointer key_min, gconstpointer key_max, gpointer data);
> gpointer g_tree_before(GTree*, gconstpointer key );
> gpointer g_tree_after(GTree*, gconstpointer key);
> 
> g_tree_traverse_interval:
> works just like g_tree_traverse, but only on values, whose keys are in the
> range between key_max and key_min.
> 
> g_tree_before:
> returns the closerst key before the given key, or NULL if none exists. The
> given key does not have to exist in the tree, but the returned will.
> 
> g_tree_after:
> works like g_tree_before, but returns the trailing key instead.
> 
> 
> I have tested these functions (somewhat), and they appear to be working...
> :)

i don't see a reason not to include these, and it seems like no one else
objects.

a few notes on the implementation though, first, get rid of the excessive
newlines in your patch. then, we put spaces around parantheses e.g.
if (foo) instead of if(foo) and g_tree_key_after (node->left, compare, key);
instead of g_tree_key_after(node->left, compare, key );

also i'm not much in favour of bloating the existing traversal functions, ala
-static gint       g_tree_node_in_order              (GTreeNode      *node,
+static gint       g_tree_node_in_order_interval      (GTreeNode      *node,
                                                     GTraverseFunc   traverse_func,
+                                                    GCompareFunc    compare,
+                                                    gconstpointer   key_min,
+                                                    gconstpointer   key_max,
                                                     gpointer        data);

simply do:

 static gint
 g_tree_node_in_order (GTreeNode *node,
 [...]
 }
+
+static gint
+g_tree_node_in_order_interval (GTreeNode *node,
+[...]
+}

to avoid a penalty for the common case due to the new functionality.
keeping the _interval variant close to the normal traversal function
will catch peoples attention to fix both, if there's some general
traversal patch to apply.

---
ciaoTJ






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