comparison src/llrb/llrbContext.c @ 72:5c4b9d116eda

use stack for code segment
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Tue, 10 Nov 2015 01:59:04 +0900
parents 368306e1bfed
children 2667c3251a00
comparison
equal deleted inserted replaced
71:6e5b0e4245cc 72:5c4b9d116eda
17 extern __code rotateLeft_stub(struct Context*); 17 extern __code rotateLeft_stub(struct Context*);
18 extern __code rotateRight_stub(struct Context*); 18 extern __code rotateRight_stub(struct Context*);
19 extern __code colorFlip_stub(struct Context*); 19 extern __code colorFlip_stub(struct Context*);
20 extern __code fixUp_stub(struct Context*); 20 extern __code fixUp_stub(struct Context*);
21 extern __code changeReference_stub(struct Context*); 21 extern __code changeReference_stub(struct Context*);
22 extern __code balance1_stub(struct Context*);
23 extern __code balance2_stub(struct Context*);
24 extern __code balance3_stub(struct Context*);
22 extern __code get_stub(struct Context*); 25 extern __code get_stub(struct Context*);
23 extern __code delete_stub(struct Context*); 26 extern __code delete_stub(struct Context*);
24 extern __code deleteMax_stub(struct Context*); 27 extern __code deleteMax_stub(struct Context*);
25 extern __code deleteMin_stub(struct Context*); 28 extern __code deleteMin_stub(struct Context*);
26 extern __code replaceNode_d_stub(struct Context*); 29 extern __code replaceNode_d_stub(struct Context*);
27 extern __code max_stub(struct Context*); 30 extern __code max_stub(struct Context*);
28 extern __code exit_code(struct Context*); 31 extern __code exit_code(struct Context*);
29 32
30 __code initLLRBContext(struct Context* context) { 33 __code initLLRBContext(struct Context* context, int num) {
31 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; 34 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE;
32 context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); 35 context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE);
33 context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE); 36 context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE);
34 context->heapStart = malloc(context->heapLimit); 37 context->heapStart = malloc(context->heapLimit);
35 38
48 context->code[RotateL] = rotateLeft_stub; 51 context->code[RotateL] = rotateLeft_stub;
49 context->code[RotateR] = rotateRight_stub; 52 context->code[RotateR] = rotateRight_stub;
50 context->code[ColorFlip] = colorFlip_stub; 53 context->code[ColorFlip] = colorFlip_stub;
51 context->code[FixUp] = fixUp_stub; 54 context->code[FixUp] = fixUp_stub;
52 context->code[ChangeRef] = changeReference_stub; 55 context->code[ChangeRef] = changeReference_stub;
56 context->code[Balance1] = balance1_stub;
57 context->code[Balance2] = balance2_stub;
58 context->code[Balance3] = balance3_stub;
53 context->code[Get] = get_stub; 59 context->code[Get] = get_stub;
54 context->code[Delete] = delete_stub; 60 /* context->code[Delete] = delete_stub; */
55 context->code[DeleteMax] = deleteMax_stub; 61 /* context->code[DeleteMax] = deleteMax_stub; */
56 // context->code[DeleteMin] = deleteMin_stub; 62 /* // context->code[DeleteMin] = deleteMin_stub; */
57 context->code[Replace_d] = replaceNode_d_stub; 63 /* context->code[Replace_d] = replaceNode_d_stub; */
58 context->code[Max] = max_stub; 64 /* context->code[Max] = max_stub; */
59 context->code[Exit] = exit_code; 65 context->code[Exit] = exit_code;
60 66
61 context->heap = context->heapStart; 67 context->heap = context->heapStart;
62 68
63 context->data[Allocate] = context->heap; 69 context->data[Allocate] = context->heap;
74 struct Tree* tree = &context->data[Tree]->tree; 80 struct Tree* tree = &context->data[Tree]->tree;
75 tree->root = 0; 81 tree->root = 0;
76 tree->current = 0; 82 tree->current = 0;
77 tree->prev = 0; 83 tree->prev = 0;
78 84
85 context->node_stack = stack_init(sizeof(union Data*), num);
86 context->code_stack = stack_init(sizeof(enum Code), 100);
79 } 87 }