Skip to contentSkip to conversation

: Add rb_last()

PATCH In review Patrick McHardy 1 participant 1 message Aug 14, 2004

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 : Add rb_last()

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 [email protected]
# [RBTREE]: Add rb_last()
#
# Signed-off-by: Patrick McHardy <[email protected]>
#

# lib/rbtree.c
#   2004/08/11 23:09:34+02:00 [email protected] +13 -0
#   [RBTREE]: Add rb_last()
# 
# include/linux/rbtree.h
#   2004/08/11 23:09:34+02:00 [email protected] +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,

lib/rbtree.c +13 -0
diff -Nru a/lib/rbtree.c b/lib/rbtree.c
@@ -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