[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42127] trunk/blender/source/blender/ blenlib/intern/DLRB_tree.c: (See http://codereview.appspot.com/5431064/ for review of patch)
Konrad Kleine
kokleine at googlemail.com
Thu Nov 24 15:58:44 CET 2011
Revision: 42127
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42127
Author: kwk
Date: 2011-11-24 14:58:42 +0000 (Thu, 24 Nov 2011)
Log Message:
-----------
(See http://codereview.appspot.com/5431064/ for review of patch)
I've written a convenient function that returns the sibling of a node in the
red-black tree implementation originally implemented by Joshua Leung.
I want to use this get_sibling() function in the future to implement the missing
removal function of the red-black tree implementation.
For now the get_sibling() function just simplifies the get_uncle() function.
Just like the rest of the red-black tree implementation this diff is based on
Wikipedia: http://en.wikipedia.org/wiki/Red%E2%80%93black_tree#Removal
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/intern/DLRB_tree.c
Modified: trunk/blender/source/blender/blenlib/intern/DLRB_tree.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/DLRB_tree.c 2011-11-24 14:30:37 UTC (rev 42126)
+++ trunk/blender/source/blender/blenlib/intern/DLRB_tree.c 2011-11-24 14:58:42 UTC (rev 42127)
@@ -287,20 +287,28 @@
return NULL;
}
+/* get the sibling node (e.g. if node is left child of parent, return right child of parent) */
+static DLRBT_Node *get_sibling(DLRBT_Node *node)
+{
+ if (node && node->parent) {
+ if (node == node->parent->left)
+ return node->parent->right;
+ else
+ return node->parent->left;
+ }
+
+ /* sibling not found */
+ return NULL;
+}
+
/* get the 'uncle' - the sibling of the parent - of the given node */
static DLRBT_Node *get_uncle (DLRBT_Node *node)
{
- DLRBT_Node *gpn= get_grandparent(node);
+ if (node)
+ /* return the child of the grandparent which isn't the node's parent */
+ return get_sibling(node->parent);
- /* return the child of the grandparent which isn't the node's parent */
- if (gpn) {
- if (gpn->left == node->parent)
- return gpn->right;
- else
- return gpn->left;
- }
-
- /* not found */
+ /* uncle not found */
return NULL;
}
More information about the Bf-blender-cvs
mailing list