netdev
[Top] [All Lists]

[PATCH 2.6 1/4]: Add rb_last()

To: "David S. Miller" <davem@xxxxxxxxxx>
Subject: [PATCH 2.6 1/4]: Add rb_last()
From: Patrick McHardy <kaber@xxxxxxxxx>
Date: Sat, 14 Aug 2004 22:00:14 +0200
Cc: netdev@xxxxxxxxxxx, devik <devik@xxxxxx>, jamal <hadi@xxxxxxxxxx>
Sender: netdev-bounce@xxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040413 Debian/1.6-5
This patch adds rb_last which returns the last element in sort-order
from a rbtree.

# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/08/11 23:09:51+02:00 kaber@xxxxxxxxxxxx 
#   [RBTREE]: Add rb_last()
#   
#   Signed-off-by: Patrick McHardy <kaber@xxxxxxxxx>
# 
# lib/rbtree.c
#   2004/08/11 23:09:34+02:00 kaber@xxxxxxxxxxxx +13 -0
#   [RBTREE]: Add rb_last()
# 
# include/linux/rbtree.h
#   2004/08/11 23:09:34+02:00 kaber@xxxxxxxxxxxx +1 -0
#   [RBTREE]: Add rb_last()
# 
diff -Nru a/include/linux/rbtree.h b/include/linux/rbtree.h
--- a/include/linux/rbtree.h    2004-08-12 23:25:04 +02:00
+++ b/include/linux/rbtree.h    2004-08-12 23:25:04 +02:00
@@ -123,6 +123,7 @@
 extern struct rb_node *rb_next(struct rb_node *);
 extern struct rb_node *rb_prev(struct rb_node *);
 extern struct rb_node *rb_first(struct rb_root *);
+extern struct rb_node *rb_last(struct rb_root *);
 
 /* Fast replacement of a single node without remove/rebalance/add/rebalance */
 extern void rb_replace_node(struct rb_node *victim, struct rb_node *new, 
diff -Nru a/lib/rbtree.c b/lib/rbtree.c
--- a/lib/rbtree.c      2004-08-12 23:25:04 +02:00
+++ b/lib/rbtree.c      2004-08-12 23:25:04 +02:00
@@ -312,6 +312,19 @@
 }
 EXPORT_SYMBOL(rb_first);
 
+struct rb_node *rb_last(struct rb_root *root)
+{
+       struct rb_node  *n;
+
+       n = root->rb_node;
+       if (!n)
+               return NULL;
+       while (n->rb_right)
+               n = n->rb_right;
+       return n;
+}
+EXPORT_SYMBOL(rb_last);
+
 struct rb_node *rb_next(struct rb_node *node)
 {
        /* If we have a right-hand child, go down and then left as far
<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH 2.6 1/4]: Add rb_last(), Patrick McHardy <=