LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Li,Rongqing" <lirongqing@baidu.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Michel Lespinasse <michel@lespinasse.org>
Cc: "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: Wed, 25 Aug 2021 16:08:06 +0000	[thread overview]
Message-ID: <e9fac96f205e4b8f94432143052f93af@baidu.com> (raw)
In-Reply-To: <YSZD6suya8fR/2uY@hirez.programming.kicks-ass.net>



>> 
>>  
>>                          10
>>                        /
>>                       5
>>                        \
>>                         10
>>  
>> The search would stop after visiting node 5, and miss the leaf which
>> is the expected node to be returned.

 thanks for explanation.

> Just to clarify; the current code *does* work here. The proposed patch
> breaks it.

true, my patch is wrong.

but rb_find_first seems have other issue.  when the key is equal, we should search right leaf, not left leaf
rb_find_first should like below

	while (node) {
		int c = cmp(key, node);

		if (c < 0) {
			node = node->rb_left;
		} else {
			if (!c)
				match = node;
			node = node->rb_right;
		}
	}
 
since the node  is inserted to right when the key is equal, see rb_add()

 -Li


  reply	other threads:[~2021-08-25 16:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-25  9:59 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 [this message]
     [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
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=e9fac96f205e4b8f94432143052f93af@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 \
    --subject='Re: 答复: [PATCH] rbtree: stop iteration early in rb_find_first' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).