Re: [PATCH 1/5] rbtree: add postorder iteration functions

From: Cody P Schafer
Date: Mon Jul 29 2013 - 13:33:27 EST


On 07/29/2013 08:01 AM, Seth Jennings wrote:
On Fri, Jul 26, 2013 at 02:13:39PM -0700, Cody P Schafer wrote:
diff --git a/lib/rbtree.c b/lib/rbtree.c
index c0e31fe..65f4eff 100644
--- a/lib/rbtree.c
+++ b/lib/rbtree.c
@@ -518,3 +518,43 @@ void rb_replace_node(struct rb_node *victim, struct rb_node *new,
*new = *victim;
}
EXPORT_SYMBOL(rb_replace_node);
+
+static struct rb_node *rb_left_deepest_node(const struct rb_node *node)
+{
+ for (;;) {
+ if (node->rb_left)
+ node = node->rb_left;

Assigning to an argument passed as const seems weird to me. I would
think it shouldn't compile but it does. I guess my understanding of
const is incomplete.


Ya, that is due to const's binding:
const struct rb_node *node1; // the thing pointed to is const
const struct rb_node node2; // node is const
struct rb_node *const node3; // node is const
const struct rb_node *const node4; // both node and the thing
// pointed too are const

And so ends up being perfectly legal (I use the first case listed here).

+ else if (node->rb_right)
+ node = node->rb_right;
+ else
+ return (struct rb_node *)node;
+ }
+}
+
+struct rb_node *rb_next_postorder(const struct rb_node *node)
+{
+ const struct rb_node *parent;
+ if (!node)
+ return NULL;
+ parent = rb_parent(node);

Again here.

Seth


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/