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/.
36 * SECTION: trees-binary
37 * @title: Balanced Binary Trees
38 * @short_description: a sorted collection of key/value pairs optimized
39 * for searching and traversing in order
41 * The #GTree structure and its associated functions provide a sorted
42 * collection of key/value pairs optimized for searching and traversing
45 * To create a new #GTree use g_tree_new().
47 * To insert a key/value pair into a #GTree use g_tree_insert().
49 * To lookup the value corresponding to a given key, use
50 * g_tree_lookup() and g_tree_lookup_extended().
52 * To find out the number of nodes in a #GTree, use g_tree_nnodes(). To
53 * get the height of a #GTree, use g_tree_height().
55 * To traverse a #GTree, calling a function for each node visited in
56 * the traversal, use g_tree_foreach().
58 * To remove a key/value pair use g_tree_remove().
60 * To destroy a #GTree, use g_tree_destroy().
65 #define MAX_GTREE_HEIGHT 40
67 typedef struct _GTreeNode GTreeNode;
72 * The <structname>GTree</structname> struct is an opaque data
73 * structure representing a <link
74 * linkend="glib-Balanced-Binary-Trees">Balanced Binary Tree</link>. It
75 * should be accessed only by using the following functions.
80 GCompareDataFunc key_compare;
81 GDestroyNotify key_destroy_func;
82 GDestroyNotify value_destroy_func;
83 gpointer key_compare_data;
90 gpointer key; /* key for this node */
91 gpointer value; /* value stored at this node */
92 GTreeNode *left; /* left subtree */
93 GTreeNode *right; /* right subtree */
94 gint8 balance; /* height (left) - height (right) */
100 static GTreeNode* g_tree_node_new (gpointer key,
102 static void g_tree_insert_internal (GTree *tree,
106 static gboolean g_tree_remove_internal (GTree *tree,
109 static GTreeNode* g_tree_node_balance (GTreeNode *node);
110 static GTreeNode *g_tree_find_node (GTree *tree,
112 static gint g_tree_node_pre_order (GTreeNode *node,
113 GTraverseFunc traverse_func,
115 static gint g_tree_node_in_order (GTreeNode *node,
116 GTraverseFunc traverse_func,
118 static gint g_tree_node_post_order (GTreeNode *node,
119 GTraverseFunc traverse_func,
121 static gpointer g_tree_node_search (GTreeNode *node,
122 GCompareFunc search_func,
124 static GTreeNode* g_tree_node_rotate_left (GTreeNode *node);
125 static GTreeNode* g_tree_node_rotate_right (GTreeNode *node);
127 static void g_tree_node_check (GTreeNode *node);
132 g_tree_node_new (gpointer key,
135 GTreeNode *node = g_slice_new (GTreeNode);
140 node->left_child = FALSE;
141 node->right_child = FALSE;
150 * @key_compare_func: the function used to order the nodes in the #GTree.
151 * It should return values similar to the standard strcmp() function -
152 * 0 if the two arguments are equal, a negative value if the first argument
153 * comes before the second, or a positive value if the first argument comes
156 * Creates a new #GTree.
158 * Return value: a new #GTree.
161 g_tree_new (GCompareFunc key_compare_func)
163 g_return_val_if_fail (key_compare_func != NULL, NULL);
165 return g_tree_new_full ((GCompareDataFunc) key_compare_func, NULL,
170 * g_tree_new_with_data:
171 * @key_compare_func: qsort()-style comparison function.
172 * @key_compare_data: data to pass to comparison function.
174 * Creates a new #GTree with a comparison function that accepts user data.
175 * See g_tree_new() for more details.
177 * Return value: a new #GTree.
180 g_tree_new_with_data (GCompareDataFunc key_compare_func,
181 gpointer key_compare_data)
183 g_return_val_if_fail (key_compare_func != NULL, NULL);
185 return g_tree_new_full (key_compare_func, key_compare_data,
191 * @key_compare_func: qsort()-style comparison function.
192 * @key_compare_data: data to pass to comparison function.
193 * @key_destroy_func: a function to free the memory allocated for the key
194 * used when removing the entry from the #GTree or %NULL if you don't
195 * want to supply such a function.
196 * @value_destroy_func: a function to free the memory allocated for the
197 * value used when removing the entry from the #GTree or %NULL if you
198 * don't want to supply such a function.
200 * Creates a new #GTree like g_tree_new() and allows to specify functions
201 * to free the memory allocated for the key and value that get called when
202 * removing the entry from the #GTree.
204 * Return value: a new #GTree.
207 g_tree_new_full (GCompareDataFunc key_compare_func,
208 gpointer key_compare_data,
209 GDestroyNotify key_destroy_func,
210 GDestroyNotify value_destroy_func)
214 g_return_val_if_fail (key_compare_func != NULL, NULL);
216 tree = g_slice_new (GTree);
218 tree->key_compare = key_compare_func;
219 tree->key_destroy_func = key_destroy_func;
220 tree->value_destroy_func = value_destroy_func;
221 tree->key_compare_data = key_compare_data;
228 static inline GTreeNode *
229 g_tree_first_node (GTree *tree)
238 while (tmp->left_child)
244 static inline GTreeNode *
245 g_tree_node_previous (GTreeNode *node)
251 if (node->left_child)
252 while (tmp->right_child)
258 static inline GTreeNode *
259 g_tree_node_next (GTreeNode *node)
265 if (node->right_child)
266 while (tmp->left_child)
273 g_tree_remove_all (GTree *tree)
278 g_return_if_fail (tree != NULL);
280 node = g_tree_first_node (tree);
284 next = g_tree_node_next (node);
286 if (tree->key_destroy_func)
287 tree->key_destroy_func (node->key);
288 if (tree->value_destroy_func)
289 tree->value_destroy_func (node->value);
290 g_slice_free (GTreeNode, node);
303 * Increments the reference count of @tree by one. It is safe to call
304 * this function from any thread.
306 * Return value: the passed in #GTree.
311 g_tree_ref (GTree *tree)
313 g_return_val_if_fail (tree != NULL, NULL);
315 g_atomic_int_inc (&tree->ref_count);
324 * Decrements the reference count of @tree by one. If the reference count
325 * drops to 0, all keys and values will be destroyed (if destroy
326 * functions were specified) and all memory allocated by @tree will be
329 * It is safe to call this function from any thread.
334 g_tree_unref (GTree *tree)
336 g_return_if_fail (tree != NULL);
338 if (g_atomic_int_dec_and_test (&tree->ref_count))
340 g_tree_remove_all (tree);
341 g_slice_free (GTree, tree);
349 * Removes all keys and values from the #GTree and decreases its
350 * reference count by one. If keys and/or values are dynamically
351 * allocated, you should either free them first or create the #GTree
352 * using g_tree_new_full(). In the latter case the destroy functions
353 * you supplied will be called on all keys and values before destroying
357 g_tree_destroy (GTree *tree)
359 g_return_if_fail (tree != NULL);
361 g_tree_remove_all (tree);
368 * @key: the key to insert.
369 * @value: the value corresponding to the key.
371 * Inserts a key/value pair into a #GTree. If the given key already exists
372 * in the #GTree its corresponding value is set to the new value. If you
373 * supplied a value_destroy_func when creating the #GTree, the old value is
374 * freed using that function. If you supplied a @key_destroy_func when
375 * creating the #GTree, the passed key is freed using that function.
377 * The tree is automatically 'balanced' as new key/value pairs are added,
378 * so that the distance from the root to every leaf is as small as possible.
381 g_tree_insert (GTree *tree,
385 g_return_if_fail (tree != NULL);
387 g_tree_insert_internal (tree, key, value, FALSE);
390 g_tree_node_check (tree->root);
397 * @key: the key to insert.
398 * @value: the value corresponding to the key.
400 * Inserts a new key and value into a #GTree similar to g_tree_insert().
401 * The difference is that if the key already exists in the #GTree, it gets
402 * replaced by the new key. If you supplied a @value_destroy_func when
403 * creating the #GTree, the old value is freed using that function. If you
404 * supplied a @key_destroy_func when creating the #GTree, the old key is
405 * freed using that function.
407 * The tree is automatically 'balanced' as new key/value pairs are added,
408 * so that the distance from the root to every leaf is as small as possible.
411 g_tree_replace (GTree *tree,
415 g_return_if_fail (tree != NULL);
417 g_tree_insert_internal (tree, key, value, TRUE);
420 g_tree_node_check (tree->root);
424 /* internal insert routine */
426 g_tree_insert_internal (GTree *tree,
432 GTreeNode *path[MAX_GTREE_HEIGHT];
435 g_return_if_fail (tree != NULL);
439 tree->root = g_tree_node_new (key, value);
450 int cmp = tree->key_compare (key, node->key, tree->key_compare_data);
454 if (tree->value_destroy_func)
455 tree->value_destroy_func (node->value);
461 if (tree->key_destroy_func)
462 tree->key_destroy_func (node->key);
468 /* free the passed key */
469 if (tree->key_destroy_func)
470 tree->key_destroy_func (key);
477 if (node->left_child)
484 GTreeNode *child = g_tree_node_new (key, value);
486 child->left = node->left;
489 node->left_child = TRUE;
499 if (node->right_child)
506 GTreeNode *child = g_tree_node_new (key, value);
508 child->right = node->right;
511 node->right_child = TRUE;
521 /* restore balance. This is the goodness of a non-recursive
522 implementation, when we are done with balancing we 'break'
523 the loop and we are done. */
526 GTreeNode *bparent = path[--idx];
527 gboolean left_node = (bparent && node == bparent->left);
528 g_assert (!bparent || bparent->left == node || bparent->right == node);
530 if (node->balance < -1 || node->balance > 1)
532 node = g_tree_node_balance (node);
536 bparent->left = node;
538 bparent->right = node;
541 if (node->balance == 0 || bparent == NULL)
545 bparent->balance -= 1;
547 bparent->balance += 1;
556 * @key: the key to remove.
558 * Removes a key/value pair from a #GTree.
560 * If the #GTree was created using g_tree_new_full(), the key and value
561 * are freed using the supplied destroy functions, otherwise you have to
562 * make sure that any dynamically allocated values are freed yourself.
563 * If the key does not exist in the #GTree, the function does nothing.
565 * Returns: %TRUE if the key was found (prior to 2.8, this function returned
569 g_tree_remove (GTree *tree,
574 g_return_val_if_fail (tree != NULL, FALSE);
576 removed = g_tree_remove_internal (tree, key, FALSE);
579 g_tree_node_check (tree->root);
588 * @key: the key to remove.
590 * Removes a key and its associated value from a #GTree without calling
591 * the key and value destroy functions.
593 * If the key does not exist in the #GTree, the function does nothing.
595 * Returns: %TRUE if the key was found (prior to 2.8, this function returned
599 g_tree_steal (GTree *tree,
604 g_return_val_if_fail (tree != NULL, FALSE);
606 removed = g_tree_remove_internal (tree, key, TRUE);
609 g_tree_node_check (tree->root);
615 /* internal remove routine */
617 g_tree_remove_internal (GTree *tree,
621 GTreeNode *node, *parent, *balance;
622 GTreeNode *path[MAX_GTREE_HEIGHT];
626 g_return_val_if_fail (tree != NULL, FALSE);
637 int cmp = tree->key_compare (key, node->key, tree->key_compare_data);
643 if (!node->left_child)
651 if (!node->right_child)
659 /* the following code is almost equal to g_tree_remove_node,
660 except that we do not have to call g_tree_node_parent. */
661 balance = parent = path[--idx];
662 g_assert (!parent || parent->left == node || parent->right == node);
663 left_node = (parent && node == parent->left);
665 if (!node->left_child)
667 if (!node->right_child)
673 parent->left_child = FALSE;
674 parent->left = node->left;
675 parent->balance += 1;
679 parent->right_child = FALSE;
680 parent->right = node->right;
681 parent->balance -= 1;
684 else /* node has a right child */
686 GTreeNode *tmp = g_tree_node_next (node);
687 tmp->left = node->left;
690 tree->root = node->right;
693 parent->left = node->right;
694 parent->balance += 1;
698 parent->right = node->right;
699 parent->balance -= 1;
703 else /* node has a left child */
705 if (!node->right_child)
707 GTreeNode *tmp = g_tree_node_previous (node);
708 tmp->right = node->right;
711 tree->root = node->left;
714 parent->left = node->left;
715 parent->balance += 1;
719 parent->right = node->left;
720 parent->balance -= 1;
723 else /* node has a both children (pant, pant!) */
725 GTreeNode *prev = node->left;
726 GTreeNode *next = node->right;
727 GTreeNode *nextp = node;
728 int old_idx = idx + 1;
731 /* path[idx] == parent */
732 /* find the immediately next node (and its parent) */
733 while (next->left_child)
735 path[++idx] = nextp = next;
739 path[old_idx] = next;
742 /* remove 'next' from the tree */
745 if (next->right_child)
746 nextp->left = next->right;
748 nextp->left_child = FALSE;
751 next->right_child = TRUE;
752 next->right = node->right;
757 /* set the prev to point to the right place */
758 while (prev->right_child)
762 /* prepare 'next' to replace 'node' */
763 next->left_child = TRUE;
764 next->left = node->left;
765 next->balance = node->balance;
772 parent->right = next;
776 /* restore balance */
780 GTreeNode *bparent = path[--idx];
781 g_assert (!bparent || bparent->left == balance || bparent->right == balance);
782 left_node = (bparent && balance == bparent->left);
784 if(balance->balance < -1 || balance->balance > 1)
786 balance = g_tree_node_balance (balance);
788 tree->root = balance;
790 bparent->left = balance;
792 bparent->right = balance;
795 if (balance->balance != 0 || !bparent)
799 bparent->balance += 1;
801 bparent->balance -= 1;
808 if (tree->key_destroy_func)
809 tree->key_destroy_func (node->key);
810 if (tree->value_destroy_func)
811 tree->value_destroy_func (node->value);
814 g_slice_free (GTreeNode, node);
824 * @key: the key to look up.
826 * Gets the value corresponding to the given key. Since a #GTree is
827 * automatically balanced as key/value pairs are added, key lookup is very
830 * Return value: the value corresponding to the key, or %NULL if the key was
834 g_tree_lookup (GTree *tree,
839 g_return_val_if_fail (tree != NULL, NULL);
841 node = g_tree_find_node (tree, key);
843 return node ? node->value : NULL;
847 * g_tree_lookup_extended:
849 * @lookup_key: the key to look up.
850 * @orig_key: returns the original key.
851 * @value: returns the value associated with the key.
853 * Looks up a key in the #GTree, returning the original key and the
854 * associated value and a #gboolean which is %TRUE if the key was found. This
855 * is useful if you need to free the memory allocated for the original key,
856 * for example before calling g_tree_remove().
858 * Return value: %TRUE if the key was found in the #GTree.
861 g_tree_lookup_extended (GTree *tree,
862 gconstpointer lookup_key,
868 g_return_val_if_fail (tree != NULL, FALSE);
870 node = g_tree_find_node (tree, lookup_key);
875 *orig_key = node->key;
877 *value = node->value;
887 * @func: the function to call for each node visited. If this function
888 * returns %TRUE, the traversal is stopped.
889 * @user_data: user data to pass to the function.
891 * Calls the given function for each of the key/value pairs in the #GTree.
892 * The function is passed the key and value of each pair, and the given
893 * @data parameter. The tree is traversed in sorted order.
895 * The tree may not be modified while iterating over it (you can't
896 * add/remove items). To remove all items matching a predicate, you need
897 * to add each item to a list in your #GTraverseFunc as you walk over
898 * the tree, then walk the list and remove each item.
901 g_tree_foreach (GTree *tree,
907 g_return_if_fail (tree != NULL);
912 node = g_tree_first_node (tree);
916 if ((*func) (node->key, node->value, user_data))
919 node = g_tree_node_next (node);
926 * @traverse_func: the function to call for each node visited. If this
927 * function returns %TRUE, the traversal is stopped.
928 * @traverse_type: the order in which nodes are visited, one of %G_IN_ORDER,
929 * %G_PRE_ORDER and %G_POST_ORDER.
930 * @user_data: user data to pass to the function.
932 * Calls the given function for each node in the #GTree.
934 * Deprecated:2.2: The order of a balanced tree is somewhat arbitrary. If you
935 * just want to visit all nodes in sorted order, use g_tree_foreach()
936 * instead. If you really need to visit nodes in a different order, consider
937 * using an <link linkend="glib-N-ary-Trees">N-ary Tree</link>.
941 * @key: a key of a #GTree node.
942 * @value: the value corresponding to the key.
943 * @data: user data passed to g_tree_traverse().
944 * @Returns: %TRUE to stop the traversal.
946 * Specifies the type of function passed to g_tree_traverse(). It is
947 * passed the key and value of each node, together with the @user_data
948 * parameter passed to g_tree_traverse(). If the function returns
949 * %TRUE, the traversal is stopped.
953 * @G_IN_ORDER: vists a node's left child first, then the node itself,
954 * then its right child. This is the one to use if you
955 * want the output sorted according to the compare
957 * @G_PRE_ORDER: visits a node, then its children.
958 * @G_POST_ORDER: visits the node's children, then the node itself.
959 * @G_LEVEL_ORDER: is not implemented for <link
960 * linkend="glib-Balanced-Binary-Trees">Balanced Binary
961 * Trees</link>. For <link
962 * linkend="glib-N-ary-Trees">N-ary Trees</link>, it
963 * vists the root node first, then its children, then
964 * its grandchildren, and so on. Note that this is less
965 * efficient than the other orders.
967 * Specifies the type of traveral performed by g_tree_traverse(),
968 * g_node_traverse() and g_node_find().
971 g_tree_traverse (GTree *tree,
972 GTraverseFunc traverse_func,
973 GTraverseType traverse_type,
976 g_return_if_fail (tree != NULL);
981 switch (traverse_type)
984 g_tree_node_pre_order (tree->root, traverse_func, user_data);
988 g_tree_node_in_order (tree->root, traverse_func, user_data);
992 g_tree_node_post_order (tree->root, traverse_func, user_data);
996 g_warning ("g_tree_traverse(): traverse type G_LEVEL_ORDER isn't implemented.");
1004 * @search_func: a function used to search the #GTree.
1005 * @user_data: the data passed as the second argument to the @search_func
1008 * Searches a #GTree using @search_func.
1010 * The @search_func is called with a pointer to the key of a key/value pair in
1011 * the tree, and the passed in @user_data. If @search_func returns 0 for a
1012 * key/value pair, then g_tree_search_func() will return the value of that
1013 * pair. If @search_func returns -1, searching will proceed among the
1014 * key/value pairs that have a smaller key; if @search_func returns 1,
1015 * searching will proceed among the key/value pairs that have a larger key.
1017 * Return value: the value corresponding to the found key, or %NULL if the key
1021 g_tree_search (GTree *tree,
1022 GCompareFunc search_func,
1023 gconstpointer user_data)
1025 g_return_val_if_fail (tree != NULL, NULL);
1028 return g_tree_node_search (tree->root, search_func, user_data);
1037 * Gets the height of a #GTree.
1039 * If the #GTree contains no nodes, the height is 0.
1040 * If the #GTree contains only one root node the height is 1.
1041 * If the root node has children the height is 2, etc.
1043 * Return value: the height of the #GTree.
1046 g_tree_height (GTree *tree)
1051 g_return_val_if_fail (tree != NULL, 0);
1061 height += 1 + MAX(node->balance, 0);
1063 if (!node->left_child)
1074 * Gets the number of nodes in a #GTree.
1076 * Return value: the number of nodes in the #GTree.
1079 g_tree_nnodes (GTree *tree)
1081 g_return_val_if_fail (tree != NULL, 0);
1083 return tree->nnodes;
1087 g_tree_node_balance (GTreeNode *node)
1089 if (node->balance < -1)
1091 if (node->left->balance > 0)
1092 node->left = g_tree_node_rotate_left (node->left);
1093 node = g_tree_node_rotate_right (node);
1095 else if (node->balance > 1)
1097 if (node->right->balance < 0)
1098 node->right = g_tree_node_rotate_right (node->right);
1099 node = g_tree_node_rotate_left (node);
1106 g_tree_find_node (GTree *tree,
1118 cmp = tree->key_compare (key, node->key, tree->key_compare_data);
1123 if (!node->left_child)
1130 if (!node->right_child)
1139 g_tree_node_pre_order (GTreeNode *node,
1140 GTraverseFunc traverse_func,
1143 if ((*traverse_func) (node->key, node->value, data))
1146 if (node->left_child)
1148 if (g_tree_node_pre_order (node->left, traverse_func, data))
1152 if (node->right_child)
1154 if (g_tree_node_pre_order (node->right, traverse_func, data))
1162 g_tree_node_in_order (GTreeNode *node,
1163 GTraverseFunc traverse_func,
1166 if (node->left_child)
1168 if (g_tree_node_in_order (node->left, traverse_func, data))
1172 if ((*traverse_func) (node->key, node->value, data))
1175 if (node->right_child)
1177 if (g_tree_node_in_order (node->right, traverse_func, data))
1185 g_tree_node_post_order (GTreeNode *node,
1186 GTraverseFunc traverse_func,
1189 if (node->left_child)
1191 if (g_tree_node_post_order (node->left, traverse_func, data))
1195 if (node->right_child)
1197 if (g_tree_node_post_order (node->right, traverse_func, data))
1201 if ((*traverse_func) (node->key, node->value, data))
1208 g_tree_node_search (GTreeNode *node,
1209 GCompareFunc search_func,
1219 dir = (* search_func) (node->key, data);
1224 if (!node->left_child)
1231 if (!node->right_child)
1240 g_tree_node_rotate_left (GTreeNode *node)
1246 right = node->right;
1248 if (right->left_child)
1249 node->right = right->left;
1252 node->right_child = FALSE;
1253 node->right = right;
1254 right->left_child = TRUE;
1258 a_bal = node->balance;
1259 b_bal = right->balance;
1264 right->balance = b_bal - 1;
1266 right->balance = a_bal + b_bal - 2;
1267 node->balance = a_bal - 1;
1272 right->balance = a_bal - 2;
1274 right->balance = b_bal - 1;
1275 node->balance = a_bal - b_bal - 1;
1282 g_tree_node_rotate_right (GTreeNode *node)
1290 if (left->right_child)
1291 node->left = left->right;
1294 node->left_child = FALSE;
1296 left->right_child = TRUE;
1300 a_bal = node->balance;
1301 b_bal = left->balance;
1306 left->balance = b_bal + 1;
1308 left->balance = a_bal + 2;
1309 node->balance = a_bal - b_bal + 1;
1314 left->balance = b_bal + 1;
1316 left->balance = a_bal + b_bal + 2;
1317 node->balance = a_bal + 1;
1325 g_tree_node_height (GTreeNode *node)
1335 if (node->left_child)
1336 left_height = g_tree_node_height (node->left);
1338 if (node->right_child)
1339 right_height = g_tree_node_height (node->right);
1341 return MAX (left_height, right_height) + 1;
1348 g_tree_node_check (GTreeNode *node)
1357 if (node->left_child)
1359 tmp = g_tree_node_previous (node);
1360 g_assert (tmp->right == node);
1363 if (node->right_child)
1365 tmp = g_tree_node_next (node);
1366 g_assert (tmp->left == node);
1372 if (node->left_child)
1373 left_height = g_tree_node_height (node->left);
1374 if (node->right_child)
1375 right_height = g_tree_node_height (node->right);
1377 balance = right_height - left_height;
1378 g_assert (balance == node->balance);
1380 if (node->left_child)
1381 g_tree_node_check (node->left);
1382 if (node->right_child)
1383 g_tree_node_check (node->right);
1388 g_tree_node_dump (GTreeNode *node,
1391 g_print ("%*s%c\n", indent, "", *(char *)node->key);
1393 if (node->left_child)
1394 g_tree_node_dump (node->left, indent + 2);
1395 else if (node->left)
1396 g_print ("%*s<%c\n", indent + 2, "", *(char *)node->left->key);
1398 if (node->right_child)
1399 g_tree_node_dump (node->right, indent + 2);
1400 else if (node->right)
1401 g_print ("%*s>%c\n", indent + 2, "", *(char *)node->right->key);
1406 g_tree_dump (GTree *tree)
1409 g_tree_node_dump (tree->root, 0);