Mercurial > hg > Members > Moririn
view src/llrb/llrbContext.c @ 77:618c03f25108
implement insert(tail recursion)
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 27 Nov 2015 02:14:25 +0900 |
parents | 97387904add9 |
children | dc6f665bb753 |
line wrap: on
line source
#include <stdlib.h> #include "llrbContext.h" extern __code code1_stub(struct Context*); extern __code code2_stub(struct Context*); extern __code code3_stub(struct Context*); extern __code code4(struct Context*); extern __code code5(struct Context*); extern __code find(struct Context*); extern __code not_find(struct Context*); extern __code code6(struct Context*); extern __code meta(struct Context*); extern __code put_stub(struct Context*); extern __code replaceNode_stub(struct Context*); extern __code insertNode_stub(struct Context*); extern __code rotateLeft_stub(struct Context*); extern __code rotateRight_stub(struct Context*); extern __code colorFlip_stub(struct Context*); extern __code fixUp_stub(struct Context*); extern __code changeReference_stub(struct Context*); extern __code balance1_stub(struct Context*); extern __code balance2_stub(struct Context*); extern __code balance3_stub(struct Context*); extern __code balance4_stub(struct Context*); extern __code balance4_1_stub(struct Context*); extern __code balance4_2_stub(struct Context*); extern __code balance5_stub(struct Context*); extern __code setRoot_stub(struct Context*); extern __code get_stub(struct Context*); extern __code findMin_stub(struct Context*); extern __code delete_stub(struct Context*); extern __code replaceNode_d1_stub(struct Context*); extern __code replaceNode_d2_stub(struct Context*); extern __code replaceNode_d3_stub(struct Context*); extern __code replaceNode_d4_stub(struct Context*); extern __code moveRedLeft1_stub(struct Context*); extern __code moveRedLeft2_stub(struct Context*); extern __code moveRedLeft3_stub(struct Context*); extern __code moveRedRight1_stub(struct Context*); extern __code moveRedRight2_stub(struct Context*); extern __code deleteMin1_stub(struct Context*); extern __code deleteMin2_stub(struct Context*); extern __code exit_code(struct Context*); __code initLLRBContext(struct Context* context, int num) { context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE); context->heapStart = malloc(context->heapLimit); context->codeNum = Exit; context->code[Code1] = code1_stub; context->code[Code2] = code2_stub; context->code[Code3] = code3_stub; context->code[Code4] = code4; context->code[Code5] = code5; context->code[Find] = find; context->code[Not_find] = not_find; context->code[Code6] = code6; context->code[Put] = put_stub; context->code[Replace] = replaceNode_stub; context->code[Insert] = insertNode_stub; context->code[RotateL] = rotateLeft_stub; context->code[RotateR] = rotateRight_stub; context->code[ColorFlip] = colorFlip_stub; context->code[FixUp] = fixUp_stub; context->code[ChangeRef] = changeReference_stub; context->code[Balance1] = balance1_stub; context->code[Balance2] = balance2_stub; context->code[Balance3] = balance3_stub; context->code[Balance4] = balance4_stub; context->code[Balance4_1] = balance4_1_stub; context->code[Balance4_2] = balance4_2_stub; context->code[Balance5] = balance5_stub; context->code[SetRoot] = setRoot_stub; context->code[Get] = get_stub; context->code[Delete] = delete_stub; context->code[FindMin] = findMin_stub; context->code[Replace_d1] = replaceNode_d1_stub; context->code[Replace_d2] = replaceNode_d2_stub; context->code[Replace_d3] = replaceNode_d3_stub; context->code[Replace_d4] = replaceNode_d4_stub; context->code[MoveRedL1] = moveRedLeft1_stub; context->code[MoveRedL2] = moveRedLeft2_stub; context->code[MoveRedL3] = moveRedLeft3_stub; context->code[MoveRedR1] = moveRedRight1_stub; context->code[MoveRedR2] = moveRedRight2_stub; context->code[DeleteMin1] = deleteMin1_stub; context->code[DeleteMin2] = deleteMin2_stub; context->code[Exit] = exit_code; context->heap = context->heapStart; context->data[Allocate] = context->heap; context->heap += sizeof(struct Allocate); context->data[Tree] = context->heap; context->heap += sizeof(struct Tree); context->data[Node] = context->heap; context->heap += sizeof(struct Node); context->dataNum = Node; struct Tree* tree = &context->data[Tree]->tree; tree->root = 0; tree->current = 0; tree->prev = 0; context->node_stack = stack_init(sizeof(union Data*), num); context->code_stack = stack_init(sizeof(enum Code), 100); }