Mercurial > hg > Gears > GearsAgda
annotate 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 |
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*); | |
72
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
22 extern __code balance1_stub(struct Context*); |
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
23 extern __code balance2_stub(struct Context*); |
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
24 extern __code balance3_stub(struct Context*); |
56 | 25 extern __code get_stub(struct Context*); |
69
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
26 extern __code delete_stub(struct Context*); |
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
27 extern __code deleteMax_stub(struct Context*); |
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
28 extern __code deleteMin_stub(struct Context*); |
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
29 extern __code replaceNode_d_stub(struct Context*); |
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
30 extern __code max_stub(struct Context*); |
19 | 31 extern __code exit_code(struct Context*); |
32 | |
72
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
33 __code initLLRBContext(struct Context* context, int num) { |
56 | 34 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE; |
23
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
35 context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE); |
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
36 context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE); |
56 | 37 context->heapStart = malloc(context->heapLimit); |
23
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
38 |
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
39 context->codeNum = Exit; |
56 | 40 context->code[Code1] = code1_stub; |
41 context->code[Code2] = code2_stub; | |
42 context->code[Code3] = code3_stub; | |
23
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
43 context->code[Code4] = code4; |
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
44 context->code[Code5] = code5; |
69
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
45 context->code[Find] = find; |
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
46 context->code[Not_find] = not_find; |
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
47 context->code[Code6] = code6; |
56 | 48 context->code[Put] = put_stub; |
49 context->code[Replace] = replaceNode_stub; | |
50 context->code[Insert] = insertNode_stub; | |
51 context->code[RotateL] = rotateLeft_stub; | |
52 context->code[RotateR] = rotateRight_stub; | |
53 context->code[ColorFlip] = colorFlip_stub; | |
54 context->code[FixUp] = fixUp_stub; | |
55 context->code[ChangeRef] = changeReference_stub; | |
72
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
56 context->code[Balance1] = balance1_stub; |
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
57 context->code[Balance2] = balance2_stub; |
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
58 context->code[Balance3] = balance3_stub; |
69
368306e1bfed
llrb deletion(not work).
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
65
diff
changeset
|
59 context->code[Get] = get_stub; |
72
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
60 /* context->code[Delete] = delete_stub; */ |
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
61 /* context->code[DeleteMax] = deleteMax_stub; */ |
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
62 /* // context->code[DeleteMin] = deleteMin_stub; */ |
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
63 /* context->code[Replace_d] = replaceNode_d_stub; */ |
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
64 /* context->code[Max] = max_stub; */ |
23
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
65 context->code[Exit] = exit_code; |
19 | 66 |
56 | 67 context->heap = context->heapStart; |
23
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
68 |
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
69 context->data[Allocate] = context->heap; |
19 | 70 context->heap += sizeof(struct Allocate); |
20 | 71 |
23
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
72 context->data[Tree] = context->heap; |
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
73 context->heap += sizeof(struct Tree); |
868c2918b634
Non Destructive llrb
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
22
diff
changeset
|
74 |
42 | 75 context->data[Node] = context->heap; |
76 context->heap += sizeof(struct Node); | |
77 | |
56 | 78 context->dataNum = Node; |
42 | 79 |
80 struct Tree* tree = &context->data[Tree]->tree; | |
81 tree->root = 0; | |
82 tree->current = 0; | |
83 tree->prev = 0; | |
56 | 84 |
72
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
85 context->node_stack = stack_init(sizeof(union Data*), num); |
5c4b9d116eda
use stack for code segment
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
69
diff
changeset
|
86 context->code_stack = stack_init(sizeof(enum Code), 100); |
19 | 87 } |