Mercurial > hg > Members > Moririn
annotate src/llrb/llrbContext.c @ 491:f985815ad032
Replace goto meta for SynchronizedQueue
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 30 Dec 2017 03:16:05 +0900 |
parents | c13575c3dbe9 |
children |
rev | line source |
---|---|
23
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
1 #include <stdlib.h> |
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
2 |
19 | 3 #include "llrbContext.h" |
23
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
4 |
56 | 5 extern __code code1_stub(struct Context*); |
6 extern __code code2_stub(struct Context*); | |
7 extern __code code3_stub(struct Context*); | |
22
4c3c0ad4a75d
add benchmark method
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
8 extern __code code4(struct Context*); |
4c3c0ad4a75d
add benchmark method
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
21
diff
changeset
|
9 extern __code code5(struct Context*); |
69
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
10 extern __code find(struct Context*); |
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
11 extern __code not_find(struct Context*); |
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
12 extern __code code6(struct Context*); |
19 | 13 extern __code meta(struct Context*); |
56 | 14 extern __code put_stub(struct Context*); |
15 extern __code replaceNode_stub(struct Context*); | |
16 extern __code insertNode_stub(struct Context*); | |
17 extern __code rotateLeft_stub(struct Context*); | |
18 extern __code rotateRight_stub(struct Context*); | |
19 extern __code colorFlip_stub(struct Context*); | |
20 extern __code fixUp_stub(struct Context*); | |
21 extern __code changeReference_stub(struct Context*); | |
81
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
22 extern __code insert1_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
23 extern __code insert2_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
24 extern __code insert3_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
25 extern __code insert4_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
26 extern __code insert4_1_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
27 extern __code insert4_2_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
28 extern __code insert5_stub(struct Context*); |
83 | 29 extern __code stackClear_stub(struct Context*); |
56 | 30 extern __code get_stub(struct Context*); |
81
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
31 extern __code search_stub(struct Context*); |
69
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
32 extern __code delete_stub(struct Context*); |
81
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
33 extern __code delete1_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
34 extern __code delete2_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
35 extern __code delete3_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
36 extern __code replaceNodeForDelete1_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
37 extern __code replaceNodeForDelete2_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
38 extern __code findMax1_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
39 extern __code findMax2_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
40 extern __code deleteCase1_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
41 extern __code deleteCase2_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
42 extern __code deleteCase3_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
43 extern __code deleteCase4_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
44 extern __code deleteCase5_stub(struct Context*); |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
45 extern __code deleteCase6_stub(struct Context*); |
19 | 46 extern __code exit_code(struct Context*); |
47 | |
72
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
48 __code initLLRBContext(struct Context* context, int num) { |
56 | 49 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; |
23
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
50 context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); |
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
51 context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE); |
56 | 52 context->heapStart = malloc(context->heapLimit); |
23
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
53 |
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
54 context->codeNum = Exit; |
73
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
55 |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
56 context->code[Code1] = code1_stub; |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
57 context->code[Code2] = code2_stub; |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
58 context->code[Code3] = code3_stub; |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
59 context->code[Code4] = code4; |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
60 context->code[Code5] = code5; |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
61 context->code[Find] = find; |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
62 context->code[Not_find] = not_find; |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
63 context->code[Code6] = code6; |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
64 context->code[Put] = put_stub; |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
65 context->code[Replace] = replaceNode_stub; |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
66 context->code[Insert] = insertNode_stub; |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
67 context->code[RotateL] = rotateLeft_stub; |
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
68 context->code[RotateR] = rotateRight_stub; |
81
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
69 context->code[InsertCase1] = insert1_stub; |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
70 context->code[InsertCase2] = insert2_stub; |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
71 context->code[InsertCase3] = insert3_stub; |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
72 context->code[InsertCase4] = insert4_stub; |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
73 context->code[InsertCase4_1] = insert4_1_stub; |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
74 context->code[InsertCase4_2] = insert4_2_stub; |
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
75 context->code[InsertCase5] = insert5_stub; |
83 | 76 context->code[StackClear] = stackClear_stub; |
77 /* context->code[Get] = get_stub; */ | |
78 /* context->code[Search] = search_stub; */ | |
79 /* context->code[Delete] = delete_stub; */ | |
80 /* context->code[Delete1] = delete1_stub; */ | |
81 /* context->code[Delete2] = delete2_stub; */ | |
82 /* context->code[Delete3] = delete3_stub; */ | |
83 /* context->code[Replace_d1] = replaceNodeForDelete1_stub; */ | |
84 /* context->code[Replace_d2] = replaceNodeForDelete2_stub; */ | |
85 /* context->code[FindMax1] = findMax1_stub; */ | |
86 /* context->code[FindMax2] = findMax2_stub; */ | |
87 /* context->code[DeleteCase1] = deleteCase1_stub; */ | |
88 /* context->code[DeleteCase2] = deleteCase2_stub; */ | |
89 /* context->code[DeleteCase3] = deleteCase3_stub; */ | |
90 /* context->code[DeleteCase4] = deleteCase4_stub; */ | |
91 /* context->code[DeleteCase5] = deleteCase5_stub; */ | |
92 /* context->code[DeleteCase6] = deleteCase6_stub; */ | |
73
2667c3251a00
implement llrb deletion
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
72
diff
changeset
|
93 context->code[Exit] = exit_code; |
19 | 94 |
56 | 95 context->heap = context->heapStart; |
23
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
96 |
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
97 context->data[Allocate] = context->heap; |
19 | 98 context->heap += sizeof(struct Allocate); |
20 | 99 |
23
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
100 context->data[Tree] = context->heap; |
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
101 context->heap += sizeof(struct Tree); |
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
102 |
42 | 103 context->data[Node] = context->heap; |
104 context->heap += sizeof(struct Node); | |
105 | |
56 | 106 context->dataNum = Node; |
42 | 107 |
108 struct Tree* tree = &context->data[Tree]->tree; | |
109 tree->root = 0; | |
110 tree->current = 0; | |
81
dc6f665bb753
implement delete(tail call). do not work
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
77
diff
changeset
|
111 tree->deleted = 0; |
56 | 112 |
83 | 113 context->node_stack = stack_init(sizeof(struct Node*), 100); |
72
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
114 context->code_stack = stack_init(sizeof(enum Code), 100); |
19 | 115 } |