Mercurial > hg > Gears > GearsAgda
changeset 337:5bca0ff563e6
remove stub from RedBlackTree.cbc
author | mir3636 |
---|---|
date | Tue, 02 May 2017 21:27:39 +0900 |
parents | f1db6fe3b200 |
children | 0d720487291f 2dd9711cd347 |
files | src/parallel_execution/RedBlackTree.cbc |
diffstat | 1 files changed, 59 insertions(+), 103 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/RedBlackTree.cbc Wed Apr 19 19:31:57 2017 +0900 +++ b/src/parallel_execution/RedBlackTree.cbc Tue May 02 21:27:39 2017 +0900 @@ -35,105 +35,74 @@ printf("\n"); } -__code putRedBlackTree(struct RedBlackTree* traverse, struct Node* node, struct Node* root, struct Node* newNode) { - printTree((union Data*)(traverse->root)); - traverse->newNode = newNode; - traverse->root = newNode; // this should done at stackClear - traverse->parent = NULL; +__code putRedBlackTree(struct RedBlackTree* tree, struct Node* node) { + struct Node* newNode = &ALLOCATE(context, Node)->Node; + struct Node* root = tree->root; + printTree((union Data*)(tree->root)); + tree->newNode = newNode; + tree->root = newNode; // this should done at stackClear + tree->parent = NULL; if (root) { - traverse->current = root; - traverse->result = compare(traverse->current, node); + tree->current = root; + tree->result = compare(tree->current, node); goto meta(context, C_replaceNode); } - goto meta(context, C_insertNode); } -__code putRedBlackTree_stub(struct Context* context) { - struct Node* newNode = &ALLOCATE(context, Node)->Node; - goto putRedBlackTree(context, - &Gearef(context, Tree)->tree->Tree.tree->RedBlackTree, - Gearef(context, Tree)->node, - Gearef(context, Tree)->tree->Tree.tree->RedBlackTree.root, - newNode - ); +__code replaceNode(struct RedBlackTree* tree, struct Stack* nodeStack) { + struct Node* oldNode = tree->current; + struct Node* newNode = tree->newNode; + tree->previous = newNode; + *newNode = *oldNode; + nodeStack->stack = (union Data*)tree->nodeStack; + nodeStack->data = (union Data*)(newNode); + nodeStack->next = C_replaceNode1; + goto meta(context, tree->nodeStack->push); } -__code replaceNode(struct RedBlackTree* traverse, struct Node* oldNode, struct Node* newNode, struct Stack* nodeStack) { - traverse->previous = newNode; - *newNode = *oldNode; - nodeStack->stack = (union Data*)traverse->nodeStack; - nodeStack->data = (union Data*)(newNode); - nodeStack->next = C_replaceNode1; - goto meta(context, traverse->nodeStack->push); -} - -__code replaceNode_stub(struct Context* context) { - goto replaceNode(context, - &Gearef(context, Tree)->tree->Tree.tree->RedBlackTree, - Gearef(context, Tree)->tree->Tree.tree->RedBlackTree.current, - //context->data[D_RedBlackTree]->RedBlackTree.newNode, - Gearef(context, Tree)->tree->Tree.tree->RedBlackTree.newNode, - Gearef(context, Stack)); -} - -__code replaceNode1(struct RedBlackTree* traverse, struct Node* node, struct Node* oldNode, struct Node* newNode, struct Node* newnewNode, int result, __code next(...)) { +__code replaceNode1(struct RedBlackTree* tree, struct Node* node, __code next(...)) { + struct Node* oldNode = tree->current; + struct Node* newNode = tree->previous; + struct Node* newnewNode = &ALLOCATE(context, Node)->Node; + int result = tree->result; if (result == EQ) { newNode->value = node->value; // go to stack clear goto meta(context, next); } else if (result == GT) { - traverse->current = oldNode->right; + tree->current = oldNode->right; newNode->right = newnewNode; } else { - traverse->current = oldNode->left; + tree->current = oldNode->left; newNode->left = newnewNode; } - traverse->newNode = newnewNode; - if (traverse->current) { - traverse->result = compare(traverse->current, node); + tree->newNode = newnewNode; + if (tree->current) { + tree->result = compare(tree->current, node); goto meta(context, C_replaceNode); } goto meta(context, C_insertNode); } -__code replaceNode1_stub(struct Context* context) { - struct Node* newnewNode = &ALLOCATE(context, Node)->Node; - goto replaceNode1(context, - &Gearef(context, Tree)->tree->Tree.tree->RedBlackTree, - Gearef(context, Tree)->node, - Gearef(context, Tree)->tree->Tree.tree->RedBlackTree.current, - Gearef(context, Tree)->tree->Tree.tree->RedBlackTree.previous, - newnewNode, - Gearef(context, Tree)->tree->Tree.tree->RedBlackTree.result, - Gearef(context, Tree)->next); -} - -__code insertNode(struct RedBlackTree* traverse, struct Stack *nodeStack, struct Node* node, struct Node* newNode) { +__code insertNode(struct RedBlackTree* tree, struct Stack* nodeStack, struct Node* node) { + struct Node* newNode = tree->newNode; *newNode = *node; newNode->color = Red; - traverse->current = newNode; - nodeStack->stack = (union Data*)traverse->nodeStack; + tree->current = newNode; + nodeStack->stack = (union Data*)tree->nodeStack; nodeStack->next = C_insertCase1; goto meta(context, traverse->nodeStack->get2); } -__code insertNode_stub(struct Context* context) { - goto insertNode(context, - &Gearef(context, Tree)->tree->Tree.tree->RedBlackTree, - Gearef(context, Stack), - Gearef(context, Tree)->node, - Gearef(context, Tree)->tree->Tree.tree->RedBlackTree.newNode); -} - -__code insertCase1(struct RedBlackTree* traverse, struct Node *parent, struct Node *grandparent) { +__code insertCase1(struct RedBlackTree* tree, struct Node *parent, struct Node *grandparent) { if (parent != NULL) { - traverse->parent = parent; - traverse->grandparent = grandparent; + tree->parent = parent; + tree->grandparent = grandparent; goto meta(context, C_insertCase2); } - traverse->root->color = Black; + tree->root->color = Black; goto meta(context, C_stackClear); } @@ -144,64 +113,55 @@ &context->data[D_Stack]->Stack.data1->Node); } -__code insertCase2(struct RedBlackTree* traverse) { - if (traverse->parent->color == Black) { +__code insertCase2(struct RedBlackTree* tree) { + if (tree->parent->color == Black) { goto meta(context, C_stackClear); } goto meta(context, C_insertCase3); } -__code insertCase2_stub(struct Context* context) { - goto insertCase2(context, &Gearef(context, Tree)->tree->Tree.tree->RedBlackTree); -} - -__code insertCase3(struct RedBlackTree* traverse, struct Stack* nodeStack) { +__code insertCase3(struct RedBlackTree* tree, struct Stack* nodeStack) { struct Node* uncle; - if (traverse->grandparent->left == traverse->parent) - uncle = traverse->grandparent->right; + if (tree->grandparent->left == tree->parent) + uncle = tree->grandparent->right; else - uncle = traverse->grandparent->left; + uncle = tree->grandparent->left; if (uncle && (uncle->color == Red)) { // do insertcase1 on grandparent, stack must be pop by two - traverse->parent->color = Black; + tree->parent->color = Black; uncle->color = Black; - traverse->grandparent->color = Red; - traverse->current = traverse->grandparent; - nodeStack->stack = (union Data*)traverse->nodeStack; + tree->grandparent->color = Red; + tree->current = tree->grandparent; + nodeStack->stack = (union Data*)tree->nodeStack; nodeStack->next = C_insertCase1; - goto meta(context, traverse->nodeStack->pop2); + goto meta(context, tree->nodeStack->pop2); } goto meta(context, C_insertCase4); } -__code insertCase3_stub(struct Context* context) { - goto insertCase3(context, &Gearef(context, Tree)->tree->Tree.tree->RedBlackTree, - Gearef(context, Stack)); -} +__code insertCase4(struct RedBlackTree* tree, struct RotateTree* rotateTree) { + struct Stack* nodeStack = tree->nodeStack; -__code insertCase4(struct RedBlackTree* traverse, struct RotateTree* rotateTree) { - struct Stack* nodeStack = traverse->nodeStack; + if ((tree->current == tree->parent->right) && (tree->parent == tree->grandparent->left)) { + tree->current = tree->current->left; + tree->parent = tree->grandparent; - if ((traverse->current == traverse->parent->right) && (traverse->parent == traverse->grandparent->left)) { - traverse->current = traverse->current->left; - traverse->parent = traverse->grandparent; - - rotateTree->traverse = traverse; + rotateTree->tree = tree; rotateTree->next = C_insertCase5; - nodeStack->stack = (union Data*)traverse->nodeStack; + nodeStack->stack = (union Data*)tree->nodeStack; nodeStack->next = C_rotateLeft; goto meta(context, nodeStack->pop); - } else if ((traverse->current == traverse->parent->left) && (traverse->parent == traverse->grandparent->right)) { - traverse->parent = traverse->grandparent; - traverse->current = traverse->current->right; + } else if ((tree->current == tree->parent->left) && (tree->parent == tree->grandparent->right)) { + tree->parent = tree->grandparent; + tree->current = tree->current->right; - rotateTree->traverse = traverse; + rotateTree->tree = tree; rotateTree->next = C_insertCase5; - nodeStack->stack = (union Data*)traverse->nodeStack; + nodeStack->stack = (union Data*)tree->nodeStack; nodeStack->next = C_rotateRight; goto meta(context, nodeStack->pop); } @@ -209,10 +169,6 @@ goto meta(context, C_insertCase5); } -__code insertCase4_stub(struct Context* context) { - goto insertCase4(context, &Gearef(context, Tree)->tree->Tree.tree->RedBlackTree, Gearef(context, RotateTree)); -} - __code insertCase5(struct RedBlackTree* traverse,struct Stack *nodeStack) { nodeStack->stack = (union Data*)traverse->nodeStack; nodeStack->next = C_insertCase51;