summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-23 20:04:30 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-23 20:04:30 (EDT)
commitbe826535a7e0437582a57aa7f4dfd8decb0c9c0e (patch)
tree85f1c24ee5532a9b5572903b1edb5954d14742fc /src
parentcb019a4ed1614349f87206a814dbea3c39b72303 (diff)
downloadmarquee-be826535a7e0437582a57aa7f4dfd8decb0c9c0e.zip
marquee-be826535a7e0437582a57aa7f4dfd8decb0c9c0e.tar.gz
marquee-be826535a7e0437582a57aa7f4dfd8decb0c9c0e.tar.bz2
mq_tree_insert_*(): Add debugging output
Diffstat (limited to 'src')
-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;
}