diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-06-17 17:32:54 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-06-17 17:32:54 +0300 |
commit | 5513da65b24a3ce77b1709acea841475115f3a7a (patch) | |
tree | 20bd4d26f20ac63ebf776cea3a0220c11258f06d /source/blender/blenlib/intern/DLRB_tree.c | |
parent | f19ecdeec64506415b9a9f75293df866691bbd28 (diff) |
Cleanup: trailing space for BLI
Diffstat (limited to 'source/blender/blenlib/intern/DLRB_tree.c')
-rw-r--r-- | source/blender/blenlib/intern/DLRB_tree.c | 140 |
1 files changed, 70 insertions, 70 deletions
diff --git a/source/blender/blenlib/intern/DLRB_tree.c b/source/blender/blenlib/intern/DLRB_tree.c index 31b4b7cd4a5..6ef77890e95 100644 --- a/source/blender/blenlib/intern/DLRB_tree.c +++ b/source/blender/blenlib/intern/DLRB_tree.c @@ -48,7 +48,7 @@ void BLI_dlrbTree_init(DLRBT_Tree *tree) { if (tree == NULL) return; - + tree->first = tree->last = tree->root = NULL; } @@ -58,11 +58,11 @@ static void recursive_tree_free_nodes(DLRBT_Node *node) /* sanity check */ if (node == NULL) return; - + /* free child nodes + subtrees */ recursive_tree_free_nodes(node->left); recursive_tree_free_nodes(node->right); - + /* free self */ MEM_freeN(node); } @@ -72,8 +72,8 @@ void BLI_dlrbTree_free(DLRBT_Tree *tree) { if (tree == NULL) return; - - /* if the list-base stuff is set, just use that (and assume its set), + + /* if the list-base stuff is set, just use that (and assume its set), * otherwise, we'll need to traverse the tree... */ if (tree->first) { @@ -84,7 +84,7 @@ void BLI_dlrbTree_free(DLRBT_Tree *tree) /* traverse tree, freeing sub-nodes */ recursive_tree_free_nodes(tree->root); } - + /* clear pointers */ tree->first = tree->last = tree->root = NULL; } @@ -97,17 +97,17 @@ static void linkedlist_sync_add_node(DLRBT_Tree *tree, DLRBT_Node *node) /* sanity checks */ if ((tree == NULL) || (node == NULL)) return; - + /* add left-node (and its subtree) */ linkedlist_sync_add_node(tree, node->left); - + /* now add self * - must remove detach from other links first * (for now, only clear own pointers) */ node->prev = node->next = NULL; BLI_addtail((ListBase *)tree, (Link *)node); - + /* finally, add right node (and its subtree) */ linkedlist_sync_add_node(tree, node->right); } @@ -118,10 +118,10 @@ void BLI_dlrbTree_linkedlist_sync(DLRBT_Tree *tree) /* sanity checks */ if (tree == NULL) return; - + /* clear list-base pointers so that the new list can be added properly */ tree->first = tree->last = NULL; - + /* start adding items from the root */ linkedlist_sync_add_node(tree, tree->root); } @@ -142,7 +142,7 @@ DLRBT_Node *BLI_dlrbTree_search(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, vo /* iteratively perform this search */ while (node && found == 0) { - /* check if traverse further or not + /* check if traverse further or not * NOTE: it is assumed that the values will be unit values only */ switch (cmp_cb(node, search_data)) { @@ -152,38 +152,38 @@ DLRBT_Node *BLI_dlrbTree_search(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, vo else found = 1; break; - + case 1: /* data greater than node */ if (node->right) node = node->right; else found = 1; break; - + default: /* data equals node */ found = 1; break; } } - + /* return the nearest matching node */ return node; -} +} /* Find the node which exactly matches the required data */ DLRBT_Node *BLI_dlrbTree_search_exact(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, void *search_data) { DLRBT_Node *node = (tree) ? tree->root : NULL; short found = 0; - + /* check that there is a comparator to use */ /* TODO: if no comparator is supplied, try using the one supplied with the tree... */ if (cmp_cb == NULL) return NULL; - + /* iteratively perform this search */ while (node && found == 0) { - /* check if traverse further or not + /* check if traverse further or not * NOTE: it is assumed that the values will be unit values only */ switch (cmp_cb(node, search_data)) { @@ -193,20 +193,20 @@ DLRBT_Node *BLI_dlrbTree_search_exact(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_ else found = -1; break; - + case 1: /* data greater than node */ if (node->right) node = node->right; else found = -1; break; - + default: /* data equals node */ found = 1; break; } } - + /* return the exactly matching node */ return (found == 1) ? (node) : (NULL); } @@ -215,25 +215,25 @@ DLRBT_Node *BLI_dlrbTree_search_exact(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_ DLRBT_Node *BLI_dlrbTree_search_prev(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, void *search_data) { DLRBT_Node *node; - + /* check that there is a comparator to use */ /* TODO: if no comparator is supplied, try using the one supplied with the tree... */ if (cmp_cb == NULL) return NULL; - + /* get the node which best matches this description */ node = BLI_dlrbTree_search(tree, cmp_cb, search_data); - + if (node) { /* if the item we're searching for is greater than the node found, we've found the match */ if (cmp_cb(node, search_data) > 0) return node; - + /* return the previous node otherwise */ /* NOTE: what happens if there is no previous node? */ return node->prev; } - + /* nothing matching was found */ return NULL; } @@ -247,20 +247,20 @@ DLRBT_Node *BLI_dlrbTree_search_next(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_c /* TODO: if no comparator is supplied, try using the one supplied with the tree... */ if (cmp_cb == NULL) return NULL; - + /* get the node which best matches this description */ node = BLI_dlrbTree_search(tree, cmp_cb, search_data); - + if (node) { /* if the item we're searching for is less than the node found, we've found the match */ if (cmp_cb(node, search_data) < 0) return node; - + /* return the previous node otherwise */ /* NOTE: what happens if there is no previous node? */ return node->next; } - + /* nothing matching was found */ return NULL; } @@ -305,7 +305,7 @@ static DLRBT_Node *get_uncle(DLRBT_Node *node) if (node) /* return the child of the grandparent which isn't the node's parent */ return get_sibling(node->parent); - + /* uncle not found */ return NULL; } @@ -317,12 +317,12 @@ static DLRBT_Node *get_uncle(DLRBT_Node *node) static void rotate_left(DLRBT_Tree *tree, DLRBT_Node *root) { DLRBT_Node **root_slot, *pivot; - + /* pivot is simply the root's right child, to become the root's parent */ pivot = root->right; if (pivot == NULL) return; - + if (root->parent) { if (root == root->parent->left) root_slot = &root->parent->left; @@ -331,17 +331,17 @@ static void rotate_left(DLRBT_Tree *tree, DLRBT_Node *root) } else root_slot = ((DLRBT_Node **)&tree->root); /* &((DLRBT_Node *)tree->root); */ - + /* - pivot's left child becomes root's right child - * - root now becomes pivot's left child + * - root now becomes pivot's left child */ root->right = pivot->left; if (pivot->left) pivot->left->parent = root; - + pivot->left = root; pivot->parent = root->parent; root->parent = pivot; - + /* make the pivot the new root */ if (root_slot) *root_slot = pivot; @@ -351,12 +351,12 @@ static void rotate_left(DLRBT_Tree *tree, DLRBT_Node *root) static void rotate_right(DLRBT_Tree *tree, DLRBT_Node *root) { DLRBT_Node **root_slot, *pivot; - + /* pivot is simply the root's left child, to become the root's parent */ pivot = root->left; if (pivot == NULL) return; - + if (root->parent) { if (root == root->parent->left) root_slot = &root->parent->left; @@ -365,17 +365,17 @@ static void rotate_right(DLRBT_Tree *tree, DLRBT_Node *root) } else root_slot = ((DLRBT_Node **)&tree->root); /* &((DLRBT_Node *)tree->root); */ - + /* - pivot's right child becomes root's left child - * - root now becomes pivot's right child + * - root now becomes pivot's right child */ root->left = pivot->right; if (pivot->right) pivot->right->parent = root; - + pivot->right = root; pivot->parent = root->parent; root->parent = pivot; - + /* make the pivot the new root */ if (root_slot) *root_slot = pivot; @@ -409,20 +409,20 @@ static void insert_check_2(DLRBT_Tree *tree, DLRBT_Node *node) /* if the parent is not black, we need to change that... */ if (node && node->parent && node->parent->tree_col) { DLRBT_Node *unc = get_uncle(node); - - /* if uncle and parent are both red, need to change them to black and make + + /* if uncle and parent are both red, need to change them to black and make * the parent black in order to satisfy the criteria of each node having the * same number of black nodes to its leaves */ if (unc && unc->tree_col) { DLRBT_Node *gp = get_grandparent(node); - + /* make the n-1 generation nodes black */ node->parent->tree_col = unc->tree_col = DLRBT_BLACK; - - /* - make the grandparent red, so that we maintain alternating red/black property + + /* - make the grandparent red, so that we maintain alternating red/black property * (it must exist, so no need to check for NULL here), - * - as the grandparent may now cause inconsistencies with the rest of the tree, + * - as the grandparent may now cause inconsistencies with the rest of the tree, * we must flush up the tree and perform checks/re-balancing/re-painting, using the * grandparent as the node of interest */ @@ -442,7 +442,7 @@ static void insert_check_2(DLRBT_Tree *tree, DLRBT_Node *node) static void insert_check_3(DLRBT_Tree *tree, DLRBT_Node *node) { DLRBT_Node *gp = get_grandparent(node); - + /* check that grandparent and node->parent exist (jut in case... really shouldn't happen on a good tree) */ if (node && node->parent && gp) { /* a left rotation will switch the roles of node and its parent, assuming that @@ -454,22 +454,22 @@ static void insert_check_3(DLRBT_Tree *tree, DLRBT_Node *node) node = node->left; } else if ((node == node->parent->left) && (node->parent == gp->right)) { - rotate_right(tree, node); + rotate_right(tree, node); node = node->right; } - - /* fix old parent's color-tagging, and perform rotation on the old parent in the + + /* fix old parent's color-tagging, and perform rotation on the old parent in the * opposite direction if needed for the current situation - * NOTE: in the code above, node pointer is changed to point to the old parent + * NOTE: in the code above, node pointer is changed to point to the old parent */ if (node) { /* get 'new' grandparent (i.e. grandparent for old-parent (node)) */ gp = get_grandparent(node); - + /* modify the coloring of the grandparent and parent so that they still satisfy the constraints */ node->parent->tree_col = DLRBT_BLACK; gp->tree_col = DLRBT_RED; - + /* if there are several nodes that all form a left chain, do a right rotation to correct this * (or a rotation in the opposite direction if they all form a right chain) */ @@ -483,7 +483,7 @@ static void insert_check_3(DLRBT_Tree *tree, DLRBT_Node *node) /* ----- */ -/* Balance the tree after the given element has been added to it +/* Balance the tree after the given element has been added to it * (using custom code, in the Binary Tree way). */ void BLI_dlrbTree_insert(DLRBT_Tree *tree, DLRBT_Node *node) @@ -491,10 +491,10 @@ void BLI_dlrbTree_insert(DLRBT_Tree *tree, DLRBT_Node *node) /* sanity checks */ if ((tree == NULL) || (node == NULL)) return; - + /* firstly, the node we just added should be red by default */ node->tree_col = DLRBT_RED; - + /* start from case 1, an trek through the tail-recursive insertion checks */ insert_check_1(tree, node); } @@ -503,12 +503,12 @@ void BLI_dlrbTree_insert(DLRBT_Tree *tree, DLRBT_Node *node) /* Add the given data to the tree, and return the node added */ /* NOTE: for duplicates, the update_cb is called (if available), and the existing node is returned */ -DLRBT_Node *BLI_dlrbTree_add(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, +DLRBT_Node *BLI_dlrbTree_add(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, DLRBT_NAlloc_FP new_cb, DLRBT_NUpdate_FP update_cb, void *data) { DLRBT_Node *parNode, *node = NULL; short new_node = 0; - + /* sanity checks */ if (tree == NULL) return NULL; @@ -524,11 +524,11 @@ DLRBT_Node *BLI_dlrbTree_add(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, /* try to find the nearest node to this one */ parNode = BLI_dlrbTree_search(tree, cmp_cb, data); - /* add new node to the BST in the 'standard way' as appropriate + /* add new node to the BST in the 'standard way' as appropriate * NOTE: we do not support duplicates in our tree... */ if (parNode) { - /* check how this new node compares with the existing ones + /* check how this new node compares with the existing ones * NOTE: it is assumed that the values will be unit values only */ switch (cmp_cb(parNode, data)) { @@ -536,7 +536,7 @@ DLRBT_Node *BLI_dlrbTree_add(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, { node = new_cb(data); new_node = 1; - + parNode->left = node; node->parent = parNode; break; @@ -545,7 +545,7 @@ DLRBT_Node *BLI_dlrbTree_add(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, { node = new_cb(data); new_node = 1; - + parNode->right = node; node->parent = parNode; break; @@ -562,21 +562,21 @@ DLRBT_Node *BLI_dlrbTree_add(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, /* no nodes in the tree yet... add a new node as the root */ node = new_cb(data); new_node = 1; - + tree->root = node; } - + /* if a new node was added, it should be tagged as red, and then balanced as appropriate */ if (new_node) { /* tag this new node as being 'red' */ node->tree_col = DLRBT_RED; - + /* perform BST balancing steps: * start from case 1, an trek through the tail-recursive insertion checks */ insert_check_1(tree, node); } - + /* return the node added */ return node; } |