From: "Li,Rongqing" <lirongqing@baidu.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Michel Lespinasse <michel@lespinasse.org>,
"dbueso@suse.de" <dbueso@suse.de>,
"mingo@kernel.org" <mingo@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: 答复: 答复: 答复: [PATCH] rbtree: stop iteration early in rb_find_first
Date: Thu, 26 Aug 2021 05:03:54 +0000 [thread overview]
Message-ID: <770bfd98d67e4c6cbfbb341d70ecf448@baidu.com> (raw)
In-Reply-To: <20210825192056.GF17784@worktop.programming.kicks-ass.net>
> You're right that rb_add() does a tail-add for elements it considers equal -- there
> is actually code in the tree that relies on this.
>
> But that doesn't mean rb_find_first() should go right, it *must*not*, because
> then it wouldn't find the 'first' aka 'leftmost' instance of the equal elements.
>
> Also, you're only considering building the tree in-order with rb_add(), trees get
> modified all the time and the pattern Michel gave is perfectly valid (also see
> rb_prev()).
>
> Sure the snippet is not a balanced tree, but you can construct the pattern as
> part of a larger tree just fine, just add some elements:
>
>
> 10(b)
> / \
> 5 10(c)
> \
> 10(a)
>
> is a tree that is balanced (remember, RB trees only require the left and right
> depths to no more than double -- as opposed to AVL trees, which have a tighter
> constraint). This tree has order: 5, 10(a), 10(b), 10(c).
> Also note that the tree rotations are stable -- they must be since they do not
> refence the order function.
>
> As such, if we rb_find_first() for 10, we must find 10(a), the leftmost
> 10 in the tree.
I see, Thanks for the explanation. Sorry for the noise.
-Li
next prev parent reply other threads:[~2021-08-26 5:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-25 9:59 [PATCH] rbtree: stop iteration early in rb_find_first Li RongQing
2021-08-25 11:39 ` Peter Zijlstra
2021-08-25 11:53 ` Michel Lespinasse
2021-08-25 11:58 ` Michel Lespinasse
2021-08-25 12:31 ` Peter Zijlstra
2021-08-25 13:21 ` Peter Zijlstra
2021-08-25 16:08 ` 答复: " Li,Rongqing
[not found] ` <90ea3457ddc7485fbc8db5f7ca5b07ab@baidu.com>
2021-08-25 17:18 ` Peter Zijlstra
2021-08-25 18:26 ` 答复: " Li,Rongqing
2021-08-25 19:20 ` Peter Zijlstra
2021-08-26 5:03 ` Li,Rongqing [this message]
2021-08-25 12:29 ` Peter Zijlstra
2021-08-25 12:32 ` Peter Zijlstra
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=770bfd98d67e4c6cbfbb341d70ecf448@baidu.com \
--to=lirongqing@baidu.com \
--cc=dbueso@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=michel@lespinasse.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox