All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rbtree: Introduce rb_remove()
@ 2024-03-28  6:45 I Hsin Cheng
  2024-03-28 19:36 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: I Hsin Cheng @ 2024-03-28  6:45 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, I Hsin Cheng

Implement the function "rb_remove()", which can perform the removal of a
certain key from the tree. Once the node with the searched key is found,
we call "rb_erase()" to perform the removal of the node, otherwise the
key doesn't exists in the tree then we return NULL.

Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
---
 include/linux/rbtree.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h
index f7edca369..1958be66f 100644
--- a/include/linux/rbtree.h
+++ b/include/linux/rbtree.h
@@ -302,6 +302,34 @@ rb_find_first(const void *key, const struct rb_root *tree,
 	return match;
 }
 
+/**
+ * rb_remove() - remove @key in tree @tree
+ * @key: key to remove
+ * @tree: tree to modify
+ * @less: operator defining the (partial) node order
+ */
+static __always_inline struct rb_node *
+rb_remove(const void *key, const struct rb_root *tree,
+	  int (*cmp)(const void *key, const struct rb_node *))
+{
+	struct rb_node *node = tree->rb_node;
+
+	while (node) {
+		int c = cmp(key, node);
+
+		if (c < 0)
+			node = node->rb_left;
+		else if (c > 0)
+			node = node->rb_right;
+		else {
+			rb_erase(node, tree->rb_node);
+			return node;
+		}
+	}
+
+	return NULL;
+}
+
 /**
  * rb_next_match() - find the next @key in @tree
  * @key: key to match
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rbtree: Introduce rb_remove()
  2024-03-28  6:45 [PATCH] rbtree: Introduce rb_remove() I Hsin Cheng
@ 2024-03-28 19:36 ` Andrew Morton
       [not found]   ` <CAH5jb=aY1y19=XAKJG4368Ey6Sq3759euKsWLkLMATO9ac55sw@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2024-03-28 19:36 UTC (permalink / raw)
  To: I Hsin Cheng; +Cc: linux-kernel

On Thu, 28 Mar 2024 14:45:39 +0800 I Hsin Cheng <richard120310@gmail.com> wrote:

> Implement the function "rb_remove()", which can perform the removal of a
> certain key from the tree. Once the node with the searched key is found,
> we call "rb_erase()" to perform the removal of the node, otherwise the
> key doesn't exists in the tree then we return NULL.
> 
> ...
>

We wouldn't merge a change like this unless there are callers of the
new function.  Please tell us everything about that.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rbtree: Introduce rb_remove()
       [not found]   ` <CAH5jb=aY1y19=XAKJG4368Ey6Sq3759euKsWLkLMATO9ac55sw@mail.gmail.com>
@ 2024-03-30  8:38     ` 鄭以新
  0 siblings, 0 replies; 3+ messages in thread
From: 鄭以新 @ 2024-03-30  8:38 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

>> We wouldn't merge a change like this unless there are callers of the
>> new function.  Please tell us everything about that.

The last reply didn't follow the requested plain text form, I'm sorry about
 that, again thanks for your patience and time on reviewing my patch.

Best Regards,

I Hsin Cheng.

鄭以新 <richard120310@gmail.com> 於 2024年3月29日 週五 下午5:10寫道:
>>
>> We wouldn't merge a change like this unless there are callers of the
>> new function.  Please tell us everything about that.
>
>
> I see, thanks for your review and the explanation.
>
> Andrew Morton <akpm@linux-foundation.org> 於 2024年3月29日 週五 上午3:36寫道:
>>
>> On Thu, 28 Mar 2024 14:45:39 +0800 I Hsin Cheng <richard120310@gmail.com> wrote:
>>
>> > Implement the function "rb_remove()", which can perform the removal of a
>> > certain key from the tree. Once the node with the searched key is found,
>> > we call "rb_erase()" to perform the removal of the node, otherwise the
>> > key doesn't exists in the tree then we return NULL.
>> >
>> > ...
>> >
>>
>> We wouldn't merge a change like this unless there are callers of the
>> new function.  Please tell us everything about that.
>>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-30  8:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28  6:45 [PATCH] rbtree: Introduce rb_remove() I Hsin Cheng
2024-03-28 19:36 ` Andrew Morton
     [not found]   ` <CAH5jb=aY1y19=XAKJG4368Ey6Sq3759euKsWLkLMATO9ac55sw@mail.gmail.com>
2024-03-30  8:38     ` 鄭以新

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.