summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorCody P Schafer <cody@linux.vnet.ibm.com>2013-09-11 14:25:10 -0700
committerMarek Szyprowski <m.szyprowski@samsung.com>2014-05-15 07:28:12 +0200
commit42d413cf5595956a6b8d4e2364b667e1d3a13fd7 (patch)
treecaf8025a9444ce38ee3483ad0f76b4328c79bfa4 /include
parent3cf01f668424a976b58af9ebbf3c5608824b464d (diff)
downloadlinux-3.10-42d413cf5595956a6b8d4e2364b667e1d3a13fd7.tar.gz
linux-3.10-42d413cf5595956a6b8d4e2364b667e1d3a13fd7.tar.bz2
linux-3.10-42d413cf5595956a6b8d4e2364b667e1d3a13fd7.zip
rbtree: add postorder iteration functions
Postorder iteration yields all of a node's children prior to yielding the node itself, and this particular implementation also avoids examining the leaf links in a node after that node has been yielded. In what I expect will be its most common usage, postorder iteration allows the deletion of every node in an rbtree without modifying the rbtree nodes (no _requirement_ that they be nulled) while avoiding referencing child nodes after they have been "deleted" (most commonly, freed). I have only updated zswap to use this functionality at this point, but numerous bits of code (most notably in the filesystem drivers) use a hand rolled postorder iteration that NULLs child links as it traverses the tree. Each of those instances could be replaced with this common implementation. 1 & 2 add rbtree postorder iteration functions. 3 adds testing of the iteration to the rbtree runtime tests 4 allows building the rbtree runtime tests as builtins 5 updates zswap. This patch: Add postorder iteration functions for rbtree. These are useful for safely freeing an entire rbtree without modifying the tree at all. Change-Id: Ibc97f0e13288030501b5e84defc6603eeb1adca6 Signed-off-by: Cody P Schafer <cody@linux.vnet.ibm.com> Reviewed-by: Seth Jennings <sjenning@linux.vnet.ibm.com> Cc: David Woodhouse <David.Woodhouse@intel.com> Cc: Rik van Riel <riel@redhat.com> Cc: Michel Lespinasse <walken@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/rbtree.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h
index 0022c1bb1e2..c467151e995 100644
--- a/include/linux/rbtree.h
+++ b/include/linux/rbtree.h
@@ -68,6 +68,10 @@ extern struct rb_node *rb_prev(const struct rb_node *);
extern struct rb_node *rb_first(const struct rb_root *);
extern struct rb_node *rb_last(const struct rb_root *);
+/* Postorder iteration - always visit the parent after its children */
+extern struct rb_node *rb_first_postorder(const struct rb_root *);
+extern struct rb_node *rb_next_postorder(const struct rb_node *);
+
/* Fast replacement of a single node without remove/rebalance/add/rebalance */
extern void rb_replace_node(struct rb_node *victim, struct rb_node *new,
struct rb_root *root);