From be826535a7e0437582a57aa7f4dfd8decb0c9c0e Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 23 Oct 2017 20:04:30 -0400 Subject: mq_tree_insert_*(): Add debugging output --- (limited to 'src') 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 . */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include "tree.h" +#include + #include +#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; } -- cgit v0.9.1