Mercurial > hg > GearsTemplate
changeset 31:dbbafae822f8
modify Non-Destructive Red Black Tree
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 02 May 2015 05:21:38 +0900 |
parents | 604135010c3a |
children | 7787f54b59ba |
files | src/llrb/llrb.c |
diffstat | 1 files changed, 11 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/llrb/llrb.c Fri May 01 18:26:05 2015 +0900 +++ b/src/llrb/llrb.c Sat May 02 05:21:38 2015 +0900 @@ -83,20 +83,19 @@ struct Node* persistentNode = &context->data[Tree]->tree.current->node; struct Tree* tree = &context->data[Tree]->tree; + int result = context->data[Tree]->tree.result; + *node = *persistentNode; - switch (context->data[Tree]->tree.result) { - case 0: + if (result == 0) { stack_pop(pstack, &tree->current); goto meta(context, RotateL); - case 1: + } else if (result == 1) { tree->current = persistentNode->right; node->right = context->heap; - break; - default: + } else { tree->current = persistentNode->left; node->left = context->heap; - break; } if (context->data[Tree]->tree.current == 0) { @@ -206,7 +205,6 @@ allocate->next = ChangeRef; allocate->node.key = node->key; - allocate->node.key = node->key; context->data[Tree]->tree.prev = context->data[Tree]->tree.current; if (stack_pop(pstack, &context->data[Tree]->tree.current) == 0) { @@ -220,14 +218,14 @@ __code changeReference(struct Context* context) { struct Node* node = &context->data[Tree]->tree.current->node; + int result = context->data[Tree]->tree.result; - switch (context->data[Tree]->tree.result) { - case 1: + if (result == 1) { + node->right = context->data[Tree]->tree.prev; + } else if (result == -1) { node->left = context->data[Tree]->tree.prev; - break; - default: - node->right = context->data[Tree]->tree.prev; - break; + } else { + perror("bad status"); } goto meta(context, RotateL);