1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
37 * SECTION: trees-binary
38 * @title: Balanced Binary Trees
39 * @short_description: a sorted collection of key/value pairs optimized
40 * for searching and traversing in order
42 * The #GTree structure and its associated functions provide a sorted
43 * collection of key/value pairs optimized for searching and traversing
46 * To create a new #GTree use g_tree_new().
48 * To insert a key/value pair into a #GTree use g_tree_insert().
50 * To lookup the value corresponding to a given key, use
51 * g_tree_lookup() and g_tree_lookup_extended().
53 * To find out the number of nodes in a #GTree, use g_tree_nnodes(). To
54 * get the height of a #GTree, use g_tree_height().
56 * To traverse a #GTree, calling a function for each node visited in
57 * the traversal, use g_tree_foreach().
59 * To remove a key/value pair use g_tree_remove().
61 * To destroy a #GTree, use g_tree_destroy().
66 #define MAX_GTREE_HEIGHT 40
68 typedef struct _GTreeNode GTreeNode;
73 * The <structname>GTree</structname> struct is an opaque data
74 * structure representing a <link
75 * linkend="glib-Balanced-Binary-Trees">Balanced Binary Tree</link>. It
76 * should be accessed only by using the following functions.
81 GCompareDataFunc key_compare;
82 GDestroyNotify key_destroy_func;
83 GDestroyNotify value_destroy_func;
84 gpointer key_compare_data;
91 gpointer key; /* key for this node */
92 gpointer value; /* value stored at this node */
93 GTreeNode *left; /* left subtree */
94 GTreeNode *right; /* right subtree */
95 gint8 balance; /* height (left) - height (right) */
101 static GTreeNode* g_tree_node_new (gpointer key,
103 static void g_tree_insert_internal (GTree *tree,
107 static gboolean g_tree_remove_internal (GTree *tree,
110 static GTreeNode* g_tree_node_balance (GTreeNode *node);
111 static GTreeNode *g_tree_find_node (GTree *tree,
113 static gint g_tree_node_pre_order (GTreeNode *node,
114 GTraverseFunc traverse_func,
116 static gint g_tree_node_in_order (GTreeNode *node,
117 GTraverseFunc traverse_func,
119 static gint g_tree_node_post_order (GTreeNode *node,
120 GTraverseFunc traverse_func,
122 static gpointer g_tree_node_search (GTreeNode *node,
123 GCompareFunc search_func,
125 static GTreeNode* g_tree_node_rotate_left (GTreeNode *node);
126 static GTreeNode* g_tree_node_rotate_right (GTreeNode *node);
128 static void g_tree_node_check (GTreeNode *node);
133 g_tree_node_new (gpointer key,
136 GTreeNode *node = g_slice_new (GTreeNode);
141 node->left_child = FALSE;
142 node->right_child = FALSE;
151 * @key_compare_func: the function used to order the nodes in the #GTree.
152 * It should return values similar to the standard strcmp() function -
153 * 0 if the two arguments are equal, a negative value if the first argument
154 * comes before the second, or a positive value if the first argument comes
157 * Creates a new #GTree.
159 * Return value: a new #GTree.
162 g_tree_new (GCompareFunc key_compare_func)
164 g_return_val_if_fail (key_compare_func != NULL, NULL);
166 return g_tree_new_full ((GCompareDataFunc) key_compare_func, NULL,
171 * g_tree_new_with_data:
172 * @key_compare_func: qsort()-style comparison function.
173 * @key_compare_data: data to pass to comparison function.
175 * Creates a new #GTree with a comparison function that accepts user data.
176 * See g_tree_new() for more details.
178 * Return value: a new #GTree.
181 g_tree_new_with_data (GCompareDataFunc key_compare_func,
182 gpointer key_compare_data)
184 g_return_val_if_fail (key_compare_func != NULL, NULL);
186 return g_tree_new_full (key_compare_func, key_compare_data,
192 * @key_compare_func: qsort()-style comparison function.
193 * @key_compare_data: data to pass to comparison function.
194 * @key_destroy_func: a function to free the memory allocated for the key
195 * used when removing the entry from the #GTree or %NULL if you don't
196 * want to supply such a function.
197 * @value_destroy_func: a function to free the memory allocated for the
198 * value used when removing the entry from the #GTree or %NULL if you
199 * don't want to supply such a function.
201 * Creates a new #GTree like g_tree_new() and allows to specify functions
202 * to free the memory allocated for the key and value that get called when
203 * removing the entry from the #GTree.
205 * Return value: a new #GTree.
208 g_tree_new_full (GCompareDataFunc key_compare_func,
209 gpointer key_compare_data,
210 GDestroyNotify key_destroy_func,
211 GDestroyNotify value_destroy_func)
215 g_return_val_if_fail (key_compare_func != NULL, NULL);
217 tree = g_slice_new (GTree);
219 tree->key_compare = key_compare_func;
220 tree->key_destroy_func = key_destroy_func;
221 tree->value_destroy_func = value_destroy_func;
222 tree->key_compare_data = key_compare_data;
229 static inline GTreeNode *
230 g_tree_first_node (GTree *tree)
239 while (tmp->left_child)
245 static inline GTreeNode *
246 g_tree_node_previous (GTreeNode *node)
252 if (node->left_child)
253 while (tmp->right_child)
259 static inline GTreeNode *
260 g_tree_node_next (GTreeNode *node)
266 if (node->right_child)
267 while (tmp->left_child)
274 g_tree_remove_all (GTree *tree)
279 g_return_if_fail (tree != NULL);
281 node = g_tree_first_node (tree);
285 next = g_tree_node_next (node);
287 if (tree->key_destroy_func)
288 tree->key_destroy_func (node->key);
289 if (tree->value_destroy_func)
290 tree->value_destroy_func (node->value);
291 g_slice_free (GTreeNode, node);
304 * Increments the reference count of @tree by one. It is safe to call
305 * this function from any thread.
307 * Return value: the passed in #GTree.
312 g_tree_ref (GTree *tree)
314 g_return_val_if_fail (tree != NULL, NULL);
316 g_atomic_int_inc (&tree->ref_count);
325 * Decrements the reference count of @tree by one. If the reference count
326 * drops to 0, all keys and values will be destroyed (if destroy
327 * functions were specified) and all memory allocated by @tree will be
330 * It is safe to call this function from any thread.
335 g_tree_unref (GTree *tree)
337 g_return_if_fail (tree != NULL);
339 if (g_atomic_int_dec_and_test (&tree->ref_count))
341 g_tree_remove_all (tree);
342 g_slice_free (GTree, tree);
350 * Removes all keys and values from the #GTree and decreases its
351 * reference count by one. If keys and/or values are dynamically
352 * allocated, you should either free them first or create the #GTree
353 * using g_tree_new_full(). In the latter case the destroy functions
354 * you supplied will be called on all keys and values before destroying
358 g_tree_destroy (GTree *tree)
360 g_return_if_fail (tree != NULL);
362 g_tree_remove_all (tree);
369 * @key: the key to insert.
370 * @value: the value corresponding to the key.
372 * Inserts a key/value pair into a #GTree. If the given key already exists
373 * in the #GTree its corresponding value is set to the new value. If you
374 * supplied a value_destroy_func when creating the #GTree, the old value is
375 * freed using that function. If you supplied a @key_destroy_func when
376 * creating the #GTree, the passed key is freed using that function.
378 * The tree is automatically 'balanced' as new key/value pairs are added,
379 * so that the distance from the root to every leaf is as small as possible.
382 g_tree_insert (GTree *tree,
386 g_return_if_fail (tree != NULL);
388 g_tree_insert_internal (tree, key, value, FALSE);
391 g_tree_node_check (tree->root);
398 * @key: the key to insert.
399 * @value: the value corresponding to the key.
401 * Inserts a new key and value into a #GTree similar to g_tree_insert().
402 * The difference is that if the key already exists in the #GTree, it gets
403 * replaced by the new key. If you supplied a @value_destroy_func when
404 * creating the #GTree, the old value is freed using that function. If you
405 * supplied a @key_destroy_func when creating the #GTree, the old key is
406 * freed using that function.
408 * The tree is automatically 'balanced' as new key/value pairs are added,
409 * so that the distance from the root to every leaf is as small as possible.
412 g_tree_replace (GTree *tree,
416 g_return_if_fail (tree != NULL);
418 g_tree_insert_internal (tree, key, value, TRUE);
421 g_tree_node_check (tree->root);
425 /* internal insert routine */
427 g_tree_insert_internal (GTree *tree,
433 GTreeNode *path[MAX_GTREE_HEIGHT];
436 g_return_if_fail (tree != NULL);
440 tree->root = g_tree_node_new (key, value);
451 int cmp = tree->key_compare (key, node->key, tree->key_compare_data);
455 if (tree->value_destroy_func)
456 tree->value_destroy_func (node->value);
462 if (tree->key_destroy_func)
463 tree->key_destroy_func (node->key);
469 /* free the passed key */
470 if (tree->key_destroy_func)
471 tree->key_destroy_func (key);
478 if (node->left_child)
485 GTreeNode *child = g_tree_node_new (key, value);
487 child->left = node->left;
490 node->left_child = TRUE;
500 if (node->right_child)
507 GTreeNode *child = g_tree_node_new (key, value);
509 child->right = node->right;
512 node->right_child = TRUE;
522 /* restore balance. This is the goodness of a non-recursive
523 implementation, when we are done with balancing we 'break'
524 the loop and we are done. */
527 GTreeNode *bparent = path[--idx];
528 gboolean left_node = (bparent && node == bparent->left);
529 g_assert (!bparent || bparent->left == node || bparent->right == node);
531 if (node->balance < -1 || node->balance > 1)
533 node = g_tree_node_balance (node);
537 bparent->left = node;
539 bparent->right = node;
542 if (node->balance == 0 || bparent == NULL)
546 bparent->balance -= 1;
548 bparent->balance += 1;
557 * @key: the key to remove.
559 * Removes a key/value pair from a #GTree.
561 * If the #GTree was created using g_tree_new_full(), the key and value
562 * are freed using the supplied destroy functions, otherwise you have to
563 * make sure that any dynamically allocated values are freed yourself.
564 * If the key does not exist in the #GTree, the function does nothing.
566 * Returns: %TRUE if the key was found (prior to 2.8, this function returned
570 g_tree_remove (GTree *tree,
575 g_return_val_if_fail (tree != NULL, FALSE);
577 removed = g_tree_remove_internal (tree, key, FALSE);
580 g_tree_node_check (tree->root);
589 * @key: the key to remove.
591 * Removes a key and its associated value from a #GTree without calling
592 * the key and value destroy functions.
594 * If the key does not exist in the #GTree, the function does nothing.
596 * Returns: %TRUE if the key was found (prior to 2.8, this function returned
600 g_tree_steal (GTree *tree,
605 g_return_val_if_fail (tree != NULL, FALSE);
607 removed = g_tree_remove_internal (tree, key, TRUE);
610 g_tree_node_check (tree->root);
616 /* internal remove routine */
618 g_tree_remove_internal (GTree *tree,
622 GTreeNode *node, *parent, *balance;
623 GTreeNode *path[MAX_GTREE_HEIGHT];
627 g_return_val_if_fail (tree != NULL, FALSE);
638 int cmp = tree->key_compare (key, node->key, tree->key_compare_data);
644 if (!node->left_child)
652 if (!node->right_child)
660 /* the following code is almost equal to g_tree_remove_node,
661 except that we do not have to call g_tree_node_parent. */
662 balance = parent = path[--idx];
663 g_assert (!parent || parent->left == node || parent->right == node);
664 left_node = (parent && node == parent->left);
666 if (!node->left_child)
668 if (!node->right_child)
674 parent->left_child = FALSE;
675 parent->left = node->left;
676 parent->balance += 1;
680 parent->right_child = FALSE;
681 parent->right = node->right;
682 parent->balance -= 1;
685 else /* node has a right child */
687 GTreeNode *tmp = g_tree_node_next (node);
688 tmp->left = node->left;
691 tree->root = node->right;
694 parent->left = node->right;
695 parent->balance += 1;
699 parent->right = node->right;
700 parent->balance -= 1;
704 else /* node has a left child */
706 if (!node->right_child)
708 GTreeNode *tmp = g_tree_node_previous (node);
709 tmp->right = node->right;
712 tree->root = node->left;
715 parent->left = node->left;
716 parent->balance += 1;
720 parent->right = node->left;
721 parent->balance -= 1;
724 else /* node has a both children (pant, pant!) */
726 GTreeNode *prev = node->left;
727 GTreeNode *next = node->right;
728 GTreeNode *nextp = node;
729 int old_idx = idx + 1;
732 /* path[idx] == parent */
733 /* find the immediately next node (and its parent) */
734 while (next->left_child)
736 path[++idx] = nextp = next;
740 path[old_idx] = next;
743 /* remove 'next' from the tree */
746 if (next->right_child)
747 nextp->left = next->right;
749 nextp->left_child = FALSE;
752 next->right_child = TRUE;
753 next->right = node->right;
758 /* set the prev to point to the right place */
759 while (prev->right_child)
763 /* prepare 'next' to replace 'node' */
764 next->left_child = TRUE;
765 next->left = node->left;
766 next->balance = node->balance;
773 parent->right = next;
777 /* restore balance */
781 GTreeNode *bparent = path[--idx];
782 g_assert (!bparent || bparent->left == balance || bparent->right == balance);
783 left_node = (bparent && balance == bparent->left);
785 if(balance->balance < -1 || balance->balance > 1)
787 balance = g_tree_node_balance (balance);
789 tree->root = balance;
791 bparent->left = balance;
793 bparent->right = balance;
796 if (balance->balance != 0 || !bparent)
800 bparent->balance += 1;
802 bparent->balance -= 1;
809 if (tree->key_destroy_func)
810 tree->key_destroy_func (node->key);
811 if (tree->value_destroy_func)
812 tree->value_destroy_func (node->value);
815 g_slice_free (GTreeNode, node);
825 * @key: the key to look up.
827 * Gets the value corresponding to the given key. Since a #GTree is
828 * automatically balanced as key/value pairs are added, key lookup is very
831 * Return value: the value corresponding to the key, or %NULL if the key was
835 g_tree_lookup (GTree *tree,
840 g_return_val_if_fail (tree != NULL, NULL);
842 node = g_tree_find_node (tree, key);
844 return node ? node->value : NULL;
848 * g_tree_lookup_extended:
850 * @lookup_key: the key to look up.
851 * @orig_key: returns the original key.
852 * @value: returns the value associated with the key.
854 * Looks up a key in the #GTree, returning the original key and the
855 * associated value and a #gboolean which is %TRUE if the key was found. This
856 * is useful if you need to free the memory allocated for the original key,
857 * for example before calling g_tree_remove().
859 * Return value: %TRUE if the key was found in the #GTree.
862 g_tree_lookup_extended (GTree *tree,
863 gconstpointer lookup_key,
869 g_return_val_if_fail (tree != NULL, FALSE);
871 node = g_tree_find_node (tree, lookup_key);
876 *orig_key = node->key;
878 *value = node->value;
888 * @func: the function to call for each node visited. If this function
889 * returns %TRUE, the traversal is stopped.
890 * @user_data: user data to pass to the function.
892 * Calls the given function for each of the key/value pairs in the #GTree.
893 * The function is passed the key and value of each pair, and the given
894 * @data parameter. The tree is traversed in sorted order.
896 * The tree may not be modified while iterating over it (you can't
897 * add/remove items). To remove all items matching a predicate, you need
898 * to add each item to a list in your #GTraverseFunc as you walk over
899 * the tree, then walk the list and remove each item.
902 g_tree_foreach (GTree *tree,
908 g_return_if_fail (tree != NULL);
913 node = g_tree_first_node (tree);
917 if ((*func) (node->key, node->value, user_data))
920 node = g_tree_node_next (node);
927 * @traverse_func: the function to call for each node visited. If this
928 * function returns %TRUE, the traversal is stopped.
929 * @traverse_type: the order in which nodes are visited, one of %G_IN_ORDER,
930 * %G_PRE_ORDER and %G_POST_ORDER.
931 * @user_data: user data to pass to the function.
933 * Calls the given function for each node in the #GTree.
935 * Deprecated:2.2: The order of a balanced tree is somewhat arbitrary. If you
936 * just want to visit all nodes in sorted order, use g_tree_foreach()
937 * instead. If you really need to visit nodes in a different order, consider
938 * using an <link linkend="glib-N-ary-Trees">N-ary Tree</link>.
942 * @key: a key of a #GTree node.
943 * @value: the value corresponding to the key.
944 * @data: user data passed to g_tree_traverse().
945 * @Returns: %TRUE to stop the traversal.
947 * Specifies the type of function passed to g_tree_traverse(). It is
948 * passed the key and value of each node, together with the @user_data
949 * parameter passed to g_tree_traverse(). If the function returns
950 * %TRUE, the traversal is stopped.
954 * @G_IN_ORDER: vists a node's left child first, then the node itself,
955 * then its right child. This is the one to use if you
956 * want the output sorted according to the compare
958 * @G_PRE_ORDER: visits a node, then its children.
959 * @G_POST_ORDER: visits the node's children, then the node itself.
960 * @G_LEVEL_ORDER: is not implemented for <link
961 * linkend="glib-Balanced-Binary-Trees">Balanced Binary
962 * Trees</link>. For <link
963 * linkend="glib-N-ary-Trees">N-ary Trees</link>, it
964 * vists the root node first, then its children, then
965 * its grandchildren, and so on. Note that this is less
966 * efficient than the other orders.
968 * Specifies the type of traveral performed by g_tree_traverse(),
969 * g_node_traverse() and g_node_find().
972 g_tree_traverse (GTree *tree,
973 GTraverseFunc traverse_func,
974 GTraverseType traverse_type,
977 g_return_if_fail (tree != NULL);
982 switch (traverse_type)
985 g_tree_node_pre_order (tree->root, traverse_func, user_data);
989 g_tree_node_in_order (tree->root, traverse_func, user_data);
993 g_tree_node_post_order (tree->root, traverse_func, user_data);
997 g_warning ("g_tree_traverse(): traverse type G_LEVEL_ORDER isn't implemented.");
1005 * @search_func: a function used to search the #GTree.
1006 * @user_data: the data passed as the second argument to the @search_func
1009 * Searches a #GTree using @search_func.
1011 * The @search_func is called with a pointer to the key of a key/value pair in
1012 * the tree, and the passed in @user_data. If @search_func returns 0 for a
1013 * key/value pair, then g_tree_search_func() will return the value of that
1014 * pair. If @search_func returns -1, searching will proceed among the
1015 * key/value pairs that have a smaller key; if @search_func returns 1,
1016 * searching will proceed among the key/value pairs that have a larger key.
1018 * Return value: the value corresponding to the found key, or %NULL if the key
1022 g_tree_search (GTree *tree,
1023 GCompareFunc search_func,
1024 gconstpointer user_data)
1026 g_return_val_if_fail (tree != NULL, NULL);
1029 return g_tree_node_search (tree->root, search_func, user_data);
1038 * Gets the height of a #GTree.
1040 * If the #GTree contains no nodes, the height is 0.
1041 * If the #GTree contains only one root node the height is 1.
1042 * If the root node has children the height is 2, etc.
1044 * Return value: the height of the #GTree.
1047 g_tree_height (GTree *tree)
1052 g_return_val_if_fail (tree != NULL, 0);
1062 height += 1 + MAX(node->balance, 0);
1064 if (!node->left_child)
1075 * Gets the number of nodes in a #GTree.
1077 * Return value: the number of nodes in the #GTree.
1080 g_tree_nnodes (GTree *tree)
1082 g_return_val_if_fail (tree != NULL, 0);
1084 return tree->nnodes;
1088 g_tree_node_balance (GTreeNode *node)
1090 if (node->balance < -1)
1092 if (node->left->balance > 0)
1093 node->left = g_tree_node_rotate_left (node->left);
1094 node = g_tree_node_rotate_right (node);
1096 else if (node->balance > 1)
1098 if (node->right->balance < 0)
1099 node->right = g_tree_node_rotate_right (node->right);
1100 node = g_tree_node_rotate_left (node);
1107 g_tree_find_node (GTree *tree,
1119 cmp = tree->key_compare (key, node->key, tree->key_compare_data);
1124 if (!node->left_child)
1131 if (!node->right_child)
1140 g_tree_node_pre_order (GTreeNode *node,
1141 GTraverseFunc traverse_func,
1144 if ((*traverse_func) (node->key, node->value, data))
1147 if (node->left_child)
1149 if (g_tree_node_pre_order (node->left, traverse_func, data))
1153 if (node->right_child)
1155 if (g_tree_node_pre_order (node->right, traverse_func, data))
1163 g_tree_node_in_order (GTreeNode *node,
1164 GTraverseFunc traverse_func,
1167 if (node->left_child)
1169 if (g_tree_node_in_order (node->left, traverse_func, data))
1173 if ((*traverse_func) (node->key, node->value, data))
1176 if (node->right_child)
1178 if (g_tree_node_in_order (node->right, traverse_func, data))
1186 g_tree_node_post_order (GTreeNode *node,
1187 GTraverseFunc traverse_func,
1190 if (node->left_child)
1192 if (g_tree_node_post_order (node->left, traverse_func, data))
1196 if (node->right_child)
1198 if (g_tree_node_post_order (node->right, traverse_func, data))
1202 if ((*traverse_func) (node->key, node->value, data))
1209 g_tree_node_search (GTreeNode *node,
1210 GCompareFunc search_func,
1220 dir = (* search_func) (node->key, data);
1225 if (!node->left_child)
1232 if (!node->right_child)
1241 g_tree_node_rotate_left (GTreeNode *node)
1247 right = node->right;
1249 if (right->left_child)
1250 node->right = right->left;
1253 node->right_child = FALSE;
1254 node->right = right;
1255 right->left_child = TRUE;
1259 a_bal = node->balance;
1260 b_bal = right->balance;
1265 right->balance = b_bal - 1;
1267 right->balance = a_bal + b_bal - 2;
1268 node->balance = a_bal - 1;
1273 right->balance = a_bal - 2;
1275 right->balance = b_bal - 1;
1276 node->balance = a_bal - b_bal - 1;
1283 g_tree_node_rotate_right (GTreeNode *node)
1291 if (left->right_child)
1292 node->left = left->right;
1295 node->left_child = FALSE;
1297 left->right_child = TRUE;
1301 a_bal = node->balance;
1302 b_bal = left->balance;
1307 left->balance = b_bal + 1;
1309 left->balance = a_bal + 2;
1310 node->balance = a_bal - b_bal + 1;
1315 left->balance = b_bal + 1;
1317 left->balance = a_bal + b_bal + 2;
1318 node->balance = a_bal + 1;
1326 g_tree_node_height (GTreeNode *node)
1336 if (node->left_child)
1337 left_height = g_tree_node_height (node->left);
1339 if (node->right_child)
1340 right_height = g_tree_node_height (node->right);
1342 return MAX (left_height, right_height) + 1;
1349 g_tree_node_check (GTreeNode *node)
1358 if (node->left_child)
1360 tmp = g_tree_node_previous (node);
1361 g_assert (tmp->right == node);
1364 if (node->right_child)
1366 tmp = g_tree_node_next (node);
1367 g_assert (tmp->left == node);
1373 if (node->left_child)
1374 left_height = g_tree_node_height (node->left);
1375 if (node->right_child)
1376 right_height = g_tree_node_height (node->right);
1378 balance = right_height - left_height;
1379 g_assert (balance == node->balance);
1381 if (node->left_child)
1382 g_tree_node_check (node->left);
1383 if (node->right_child)
1384 g_tree_node_check (node->right);
1389 g_tree_node_dump (GTreeNode *node,
1392 g_print ("%*s%c\n", indent, "", *(char *)node->key);
1394 if (node->left_child)
1395 g_tree_node_dump (node->left, indent + 2);
1396 else if (node->left)
1397 g_print ("%*s<%c\n", indent + 2, "", *(char *)node->left->key);
1399 if (node->right_child)
1400 g_tree_node_dump (node->right, indent + 2);
1401 else if (node->right)
1402 g_print ("%*s>%c\n", indent + 2, "", *(char *)node->right->key);
1407 g_tree_dump (GTree *tree)
1410 g_tree_node_dump (tree->root, 0);
1415 #define __G_TREE_C__
1416 #include "galiasdef.c"