All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: linux-kernel@vger.kernel.org
Cc: Rob Landley <rob@landley.net>
Subject: [PATCH] Corrections to Documentation/rbtree.txt
Date: Thu, 20 Mar 2008 15:29:57 +0000	[thread overview]
Message-ID: <47E282F5.6090703@mev.co.uk> (raw)

From: Ian Abbott <abbotti@mev.co.uk>

The description of the rb_entry() macro in Documentation/rbtree.txt seems incorrect.
This patch improves it (hopefully).  Also I changed the example code to call the
previous 'my_search()' example instead of an undefined 'mysearch()'.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
--- linux-2.6.24/Documentation/rbtree.txt.orig	2008-01-24 22:58:37.000000000 +0000
+++ linux-2.6.24/Documentation/rbtree.txt	2008-03-20 15:14:55.000000000 +0000
@@ -64,8 +64,8 @@
   };
 
 When dealing with a pointer to the embedded struct rb_node, the containing data
-structure may be accessed with the standard container_of() macro.  In addition,
-individual members may be accessed directly via rb_entry(node, type, member).
+structure may be accessed with the rb_entry() macro, which is a synonym for the
+standard container_of() macro.
 
 At the root of each rbtree is an rb_root structure, which is initialized to be
 empty via:
@@ -85,7 +85,7 @@
   	struct rb_node *node = root->rb_node;
 
   	while (node) {
-  		struct mytype *data = container_of(node, struct mytype, node);
+  		struct mytype *data = rb_entry(node, struct mytype, node);
 		int result;
 
 		result = strcmp(string, data->keystring);
@@ -118,7 +118,7 @@
 
   	/* Figure out where to put new node */
   	while (*new) {
-  		struct mytype *this = container_of(*new, struct mytype, node);
+  		struct mytype *this = rb_entry(*new, struct mytype, node);
   		int result = strcmp(data->keystring, this->keystring);
 
 		parent = *new;
@@ -146,7 +146,7 @@
 
 Example:
 
-  struct mytype *data = mysearch(mytree, "walrus");
+  struct mytype *data = my_search(mytree, "walrus");
 
   if (data) {
   	rb_erase(data->node, mytree);
@@ -180,13 +180,11 @@
 NULL when there are no more nodes left.
 
 The iterator functions return a pointer to the embedded struct rb_node, from
-which the containing data structure may be accessed with the container_of()
-macro, and individual members may be accessed directly via
-rb_entry(node, type, member).
+which the containing data structure may be accessed with the rb_entry() macro.
 
 Example:
 
   struct rb_node *node;
   for (node = rb_first(&mytree); node; node = rb_next(node))
-  	printk("key=%s\n", rb_entry(node, int, keystring));
+  	printk("key=%s\n", rb_entry(node, struct mytype, node)->keystring);
 



             reply	other threads:[~2008-03-20 16:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-20 15:29 Ian Abbott [this message]
2008-03-20 18:39 ` [PATCH] Corrections to Documentation/rbtree.txt Rob Landley
2008-03-25 11:02   ` Ian Abbott
2008-03-25 18:24     ` Rob Landley
2008-03-26 14:09       ` Ian Abbott
2008-03-25 11:29   ` Ian Abbott

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=47E282F5.6090703@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rob@landley.net \
    /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.