From 4fb37b1ef103fd9470a991cd334f2d3c99b52baf Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 23 Oct 2017 23:38:44 -0400 Subject: mq_tree_foreach_from(): Fix tree traversal --- (limited to 'src') diff --git a/src/tree.c b/src/tree.c index 0034d09..472e0ef 100644 --- a/src/tree.c +++ b/src/tree.c @@ -214,7 +214,7 @@ mq_tree_seek(MqTree *node, gint offset) } static gboolean -foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), +foreach_down(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data) { for (; node; node = node->next) { @@ -225,7 +225,7 @@ foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), } if (node->first_child) { - if (foreach(node->first_child, cb, user_data) == + if (foreach_down(node->first_child, cb, user_data) == MQ_TREE_STOP) { return MQ_TREE_STOP; } @@ -241,29 +241,22 @@ mq_tree_foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), { print_head("foreach", node); - foreach(node->root->first_child, cb, user_data); + foreach_down(node->root->first_child, cb, user_data); } static gboolean -foreach_from(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), +foreach_up(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data) { - for (; node; node = node->next) { - print_node(node); - if (cb(node, user_data) == MQ_TREE_STOP) { + if (node->next) { + if (foreach_down(node->next, cb, user_data) == MQ_TREE_STOP) { return MQ_TREE_STOP; } - if (node->first_child) { - if (foreach_from(node->first_child, cb, user_data) == - MQ_TREE_STOP) { - return MQ_TREE_STOP; - } - } - if (node->parent && node->parent->next) { - if (foreach_from(node->parent->next, cb, user_data) == - MQ_TREE_STOP) { - return MQ_TREE_STOP; - } + } + + if (node->parent) { + if (foreach_up(node->parent, cb, user_data) == MQ_TREE_STOP) { + return MQ_TREE_STOP; } } @@ -276,5 +269,7 @@ mq_tree_foreach_from(MqTree *node, { print_head("foreach from", node); - foreach_from(node, cb, user_data); + if (foreach_down(node, cb, user_data) == MQ_TREE_CONTINUE) { + foreach_up(node, cb, user_data); + } } -- cgit v0.9.1