diff mbox

[22/28] add a function to browse at reverse order the tree

Message ID 1308256197-29155-22-git-send-email-daniel.lezcano@linaro.org
State Accepted
Headers show

Commit Message

Daniel Lezcano June 16, 2011, 8:29 p.m. UTC
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 tree.c |   14 ++++++++++++++
 tree.h |    2 ++
 2 files changed, 16 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/tree.c b/tree.c
index 0a9c119..516e832 100644
--- a/tree.c
+++ b/tree.c
@@ -224,6 +224,20 @@  int tree_for_each(struct tree *tree, tree_cb_t cb, void *data)
 	return tree_for_each(tree->next, cb, data);
 }
 
+int tree_for_each_reverse(struct tree *tree, tree_cb_t cb, void *data)
+{
+	if (!tree)
+		return 0;
+
+	if (cb(tree, data))
+		return -1;
+
+	if (tree_for_each_reverse(tree->prev, cb, data))
+		return -1;
+
+	return tree_for_each_reverse(tree->parent, cb, data);
+}
+
 int tree_for_each_parent(struct tree *tree, tree_cb_t cb, void *data)
 {
 	if (!tree)
diff --git a/tree.h b/tree.h
index 176dd23..2af4a5a 100644
--- a/tree.h
+++ b/tree.h
@@ -46,4 +46,6 @@  extern struct tree *tree_find(struct tree *tree, const char *name);
 
 extern int tree_for_each(struct tree *tree, tree_cb_t cb, void *data);
 
+extern int tree_for_each_reverse(struct tree *tree, tree_cb_t cb, void *data);
+
 extern int tree_for_each_parent(struct tree *tree, tree_cb_t cb, void *data);