From: David Woodhouse <dwmw2@infradead.org>
To: torvalds@transmeta.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] rb_prev and rb_next.
Date: Fri, 30 Aug 2002 17:19:19 +0100 [thread overview]
Message-ID: <2559.1030724359@redhat.com> (raw)
Functions to find the next or previous item in an rbtree. I accidentally
violated the coding style of the file by letting a comment slip in; I can
remove it if that's a problem :)
===== lib/rbtree.c 1.2 vs edited =====
--- 1.2/lib/rbtree.c Wed Mar 27 13:07:17 2002
+++ edited/lib/rbtree.c Fri Aug 30 17:13:42 2002
@@ -294,3 +294,43 @@
__rb_erase_color(child, parent, root);
}
EXPORT_SYMBOL(rb_erase);
+
+rb_node_t *rb_next(rb_node_t *node)
+{
+ /* If we have a right-hand child, go down and then left as far
+ as we can. */
+ if (node->rb_right) {
+ node = node->rb_right;
+ while (node->rb_left)
+ node=node->rb_left;
+ return node;
+ }
+
+ /* No right-hand children. Everything down and left is
+ smaller than us, so any 'next' node must be in the general
+ direction of our parent. Go up the tree; any time the
+ ancestor is a right-hand child of its parent, keep going
+ up. First time it's a left-hand child of its parent, said
+ parent is our 'next' node. */
+ while (node->rb_parent && node == node->rb_parent->rb_right)
+ node = node->rb_parent;
+
+ return node->rb_parent;
+}
+EXPORT_SYMBOL(rb_next);
+
+rb_node_t *rb_prev (rb_node_t *node)
+{
+ if (node->rb_left) {
+ node = node->rb_left;
+ while(node->rb_right)
+ node = node->rb_right;
+ return node;
+ }
+
+ while (node->rb_parent && node == node->rb_parent->rb_left)
+ node = node->rb_parent;
+
+ return node->rb_parent;
+}
+EXPORT_SYMBOL(rb_prev);
===== include/linux/rbtree.h 1.1 vs edited =====
--- 1.1/include/linux/rbtree.h Tue Feb 5 20:18:53 2002
+++ edited/include/linux/rbtree.h Fri Aug 30 17:03:06 2002
@@ -120,6 +120,8 @@
extern void rb_insert_color(rb_node_t *, rb_root_t *);
extern void rb_erase(rb_node_t *, rb_root_t *);
+extern rb_node_t *rb_next(rb_node_t *);
+extern rb_node_t *rb_prev(rb_node_t *);
static inline void rb_link_node(rb_node_t * node, rb_node_t * parent, rb_node_t ** rb_link)
{
--
dwmw2
reply other threads:[~2002-08-30 16:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2559.1030724359@redhat.com \
--to=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.