[asterisk-commits] rmudgett: branch rmudgett/ao2_red_black r374212 - in /team/rmudgett/ao2_red_b...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 2 12:13:54 CDT 2012


Author: rmudgett
Date: Tue Oct  2 12:13:49 2012
New Revision: 374212

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=374212
Log:
Address mmichelson's review comments.

Modified:
    team/rmudgett/ao2_red_black/include/asterisk/astobj2.h
    team/rmudgett/ao2_red_black/main/astobj2.c

Modified: team/rmudgett/ao2_red_black/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ao2_red_black/include/asterisk/astobj2.h?view=diff&rev=374212&r1=374211&r2=374212
==============================================================================
--- team/rmudgett/ao2_red_black/include/asterisk/astobj2.h (original)
+++ team/rmudgett/ao2_red_black/include/asterisk/astobj2.h Tue Oct  2 12:13:49 2012
@@ -937,7 +937,7 @@
 	/*! \brief Traverse in descending order (Last to first container object) */
 	OBJ_ORDER_DESCENDING = (1 << 8),
 	/*!
-	 * \brief Traverse in pre-order (Node then childeren, for tree container)
+	 * \brief Traverse in pre-order (Node then children, for tree container)
 	 *
 	 * \note For non-tree containers, it is up to the container type
 	 * to make the best interpretation of the order.  For list and
@@ -946,7 +946,7 @@
 	 */
 	OBJ_ORDER_PRE = (2 << 8),
 	/*!
-	 * \brief Traverse in post-order (Childeren then node, for tree container)
+	 * \brief Traverse in post-order (Children then node, for tree container)
 	 *
 	 * \note For non-tree containers, it is up to the container type
 	 * to make the best interpretation of the order.  For list and

Modified: team/rmudgett/ao2_red_black/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/ao2_red_black/main/astobj2.c?view=diff&rev=374212&r1=374211&r2=374212
==============================================================================
--- team/rmudgett/ao2_red_black/main/astobj2.c (original)
+++ team/rmudgett/ao2_red_black/main/astobj2.c Tue Oct  2 12:13:49 2012
@@ -3477,6 +3477,11 @@
 	}
 }
 
+enum empty_node_direction {
+	GO_LEFT,
+	GO_RIGHT,
+};
+
 /*!
  * \internal
  * \brief Determine which way to go from an empty node.
@@ -3490,10 +3495,9 @@
  *   OBJ_KEY - if set, 'obj_right', is a search key item that is not an object.
  *   OBJ_PARTIAL_KEY - if set, 'obj_right', is a partial search key item that is not an object.
  *
- * \retval TRUE if go left.
- * \retval FALSE if go right.
- */
-static int rb_find_empty_direction(struct rbtree_node *empty, ao2_sort_fn *sort_fn, void *obj_right, enum search_flags flags)
+ * \return enum empty_node_direction to proceed.
+ */
+static enum empty_node_direction rb_find_empty_direction(struct rbtree_node *empty, ao2_sort_fn *sort_fn, void *obj_right, enum search_flags flags)
 {
 	int cmp;
 	struct rbtree_node *cur;
@@ -3501,34 +3505,30 @@
 
 	/* Try for a quick definite go left. */
 	if (!empty->left) {
-		/* The empty node has no left child.  Go right. */
-		return 0;
+		/* The empty node has no left child. */
+		return GO_RIGHT;
 	}
 	right_most = rb_node_most_right(empty->left);
 	if (right_most->common.obj) {
 		cmp = sort_fn(right_most->common.obj, obj_right, flags);
 		if (cmp < 0) {
-			/* Go right. */
-			return 0;
-		}
-		/* Go left. */
-		return 1;
+			return GO_RIGHT;
+		}
+		return GO_LEFT;
 	}
 
 	/* Try for a quick definite go right. */
 	if (!empty->right) {
-		/* The empty node has no right child.  Go left. */
-		return 1;
+		/* The empty node has no right child. */
+		return GO_LEFT;
 	}
 	cur = rb_node_most_left(empty->right);
 	if (cur->common.obj) {
 		cmp = sort_fn(cur->common.obj, obj_right, flags);
 		if (cmp <= 0) {
-			/* Go right. */
-			return 0;
-		}
-		/* Go left. */
-		return 1;
+			return GO_RIGHT;
+		}
+		return GO_LEFT;
 	}
 
 	/*
@@ -3545,8 +3545,8 @@
 			/* Find the parent that the node is a right child of. */
 			for (;;) {
 				if (cur->parent == empty) {
-					/* Go right.  The left side of the empty node is all empty nodes. */
-					return 0;
+					/* The left side of the empty node is all empty nodes. */
+					return GO_RIGHT;
 				}
 				if (cur->parent->right == cur) {
 					/* We are the right child.  The parent is the previous node. */
@@ -3560,11 +3560,9 @@
 		if (cur->common.obj) {
 			cmp = sort_fn(cur->common.obj, obj_right, flags);
 			if (cmp < 0) {
-				/* Go right. */
-				return 0;
-			}
-			/* Go left. */
-			return 1;
+				return GO_RIGHT;
+			}
+			return GO_LEFT;
 		}
 	}
 }
@@ -3584,6 +3582,11 @@
  *      a  Ch                     N   c
  *        / \                    / \
  *       b   c                  a   b
+ *
+ * N = node
+ * Ch = child
+ * p = parent
+ * a,b,c = other nodes that are unaffected by the rotation.
  *
  * \note It is assumed that the node's right child exists.
  *
@@ -3634,6 +3637,11 @@
  *      a  N                      Ch  c
  *        / \                    / \
  *       b   c                  a   b
+ *
+ * N = node
+ * Ch = child
+ * p = parent
+ * a,b,c = other nodes that are unaffected by the rotation.
  *
  * \note It is assumed that the node's left child exists.
  *
@@ -4207,7 +4215,8 @@
 	for (;;) {
 		if (!cur->common.obj) {
 			/* Which direction do we go to insert this node? */
-			if (rb_find_empty_direction(cur, sort_fn, node->common.obj, OBJ_POINTER)) {
+			if (rb_find_empty_direction(cur, sort_fn, node->common.obj, OBJ_POINTER)
+				== GO_LEFT) {
 				if (cur->left) {
 					cur = cur->left;
 					continue;
@@ -4568,7 +4577,8 @@
 	for (;;) {
 		if (!node->common.obj) {
 			/* Which direction do we go to find the node? */
-			if (rb_find_empty_direction(node, sort_fn, obj_right, sort_flags)) {
+			if (rb_find_empty_direction(node, sort_fn, obj_right, sort_flags)
+				== GO_LEFT) {
 				next = node->left;
 			} else {
 				next = node->right;




More information about the asterisk-commits mailing list