Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 1 Mar 2009 04:57:24 +0000 (UTC)
From:      Bruce M Simpson <bms@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r189204 - head/sys/sys
Message-ID:  <200903010457.n214vODg030949@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bms
Date: Sun Mar  1 04:57:23 2009
New Revision: 189204
URL: http://svn.freebsd.org/changeset/base/189204

Log:
  In sys/tree.h:
   * Add RB_FOREACH_FROM() which continues traversal *at*
     the y-node provided. There is no pre-increment.
   * Nuke RB_FOREACH_SAFE as it was buggy; it would omit the final node.
   * Replace RB_FOREACH_SAFE() with a working implementation
     derived from RB_FOREACH_FROM().
     The key observation is that we now only check the loop-control
     variable, but still cache the next member pointer.
   * Add RB_FOREACH_REVERSE_FROM() which continues backwards
     traversal *at* the y-node provided. There is no pre-increment.
     Typically this is used to back out of allocations made
     whilst walking an RB-tree.
   * Add RB_FOREACH_REVERSE_SAFE() which performs insertion and
     deletion safe backwards traversal.

Modified:
  head/sys/sys/tree.h

Modified: head/sys/sys/tree.h
==============================================================================
--- head/sys/sys/tree.h	Sun Mar  1 04:49:42 2009	(r189203)
+++ head/sys/sys/tree.h	Sun Mar  1 04:57:23 2009	(r189204)
@@ -737,9 +737,14 @@ name##_RB_MINMAX(struct name *head, int 
 	     (x) != NULL;						\
 	     (x) = name##_RB_NEXT(x))
 
+#define RB_FOREACH_FROM(x, name, y)					\
+	for ((x) = (y);							\
+	    ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL);	\
+	     (x) = (y))
+
 #define RB_FOREACH_SAFE(x, name, head, y)				\
 	for ((x) = RB_MIN(name, head);					\
-	     (x) != NULL && ((y) = name##_RB_NEXT(x));			\
+	    ((x) != NULL) && ((y) = name##_RB_NEXT(x), (x) != NULL);	\
 	     (x) = (y))
 
 #define RB_FOREACH_REVERSE(x, name, head)				\
@@ -747,4 +752,14 @@ name##_RB_MINMAX(struct name *head, int 
 	     (x) != NULL;						\
 	     (x) = name##_RB_PREV(x))
 
+#define RB_FOREACH_REVERSE_FROM(x, name, y)				\
+	for ((x) = (y);							\
+	    ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL);	\
+	     (x) = (y))
+
+#define RB_FOREACH_REVERSE_SAFE(x, name, head, y)			\
+	for ((x) = RB_MAX(name, head);					\
+	    ((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL);	\
+	     (x) = (y))
+
 #endif	/* _SYS_TREE_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200903010457.n214vODg030949>