summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tree.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/tree.c b/src/tree.c
index 7479e80..75ea06f 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -19,10 +19,55 @@
* along with Marquee. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include "tree.h"
+#include <inttypes.h>
+
#include <glib.h>
+#if MQ_TREE_DEBUG
+
+static void
+print_tree_recurse(MqTree *node, gsize indent)
+{
+ gsize i;
+
+ for (; node; node = node->next) {
+ for (i = 0; i < indent; ++i) {
+ g_print("\t");
+ }
+ g_print("\t0x%" PRIxPTR "\n", (uintptr_t) node);
+
+ if (node->first_child) {
+ print_tree_recurse(node->first_child, indent + 1);
+ }
+
+ if (node->parent && node->parent->next) {
+ print_tree_recurse(node->parent->next, indent + 1);
+ }
+ }
+}
+
+static void
+print_tree(MqTree *node)
+{
+ node = node->root;
+
+ g_print("New tree (size %d):\n", node->size);
+
+ print_tree_recurse(node, 0);
+}
+
+#else /* MQ_TREE_DEBUG */
+
+#define print_tree(node)
+
+#endif /* MQ_TREE_DEBUG */
+
MqTree *
mq_tree_insert_root_allocated(MqTree *node, gpointer data)
{
@@ -83,6 +128,8 @@ mq_tree_insert_child_allocated(MqTree *node, MqTree *parent, gpointer data)
node->data = data;
+ print_tree(node);
+
return node;
}
@@ -111,6 +158,8 @@ mq_tree_insert_sibling_allocated(MqTree *node, MqTree *sibling, gpointer data)
node->data = data;
+ print_tree(node);
+
return node;
}