annotate src/insert_verification/akashaLLRBContext.c @ 7:24ae2641fec5

Show tree in llrb
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Tue, 15 Mar 2016 11:52:37 +0900
parents 3f00d95339a7
children e864ede359cc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdlib.h>
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "akashaLLRBContext.h"
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
6
3f00d95339a7 Use llrb in akasha
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
5 extern __code insertOnce_stub(struct Context*);
7
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
6 extern __code showTree_stub(struct Context*);
6
3f00d95339a7 Use llrb in akasha
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
7
3f00d95339a7 Use llrb in akasha
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
8 /* definitions from llrb */
4
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 extern __code meta(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 extern __code put_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 extern __code replaceNode_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 extern __code insertNode_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 extern __code rotateLeft_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 extern __code rotateRight_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 extern __code colorFlip_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 extern __code fixUp_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 extern __code changeReference_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 extern __code insert1_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 extern __code insert2_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 extern __code insert3_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 extern __code insert4_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 extern __code insert4_1_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 extern __code insert4_2_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 extern __code insert5_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 extern __code stackClear_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 extern __code get_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 extern __code search_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 extern __code delete_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 extern __code delete1_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 extern __code delete2_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 extern __code delete3_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 extern __code replaceNodeForDelete1_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 extern __code replaceNodeForDelete2_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 extern __code findMax1_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 extern __code findMax2_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 extern __code deleteCase1_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 extern __code deleteCase2_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 extern __code deleteCase3_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 extern __code deleteCase4_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 extern __code deleteCase5_stub(struct Context*);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 extern __code deleteCase6_stub(struct Context*);
6
3f00d95339a7 Use llrb in akasha
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
42 extern __code exitCode(struct Context*);
4
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
6
3f00d95339a7 Use llrb in akasha
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
44 __code initLLRBContext(struct Context* context) {
4
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE;
6
3f00d95339a7 Use llrb in akasha
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
46 context->code = malloc(sizeof(__code*)*ALLOCATE_SIZE);
3f00d95339a7 Use llrb in akasha
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
47 context->data = malloc(sizeof(union Data*)*ALLOCATE_SIZE);
4
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 context->heapStart = malloc(context->heapLimit);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 context->codeNum = Exit;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
6
3f00d95339a7 Use llrb in akasha
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
52 context->code[InsertOnce] = insertOnce_stub;
7
24ae2641fec5 Show tree in llrb
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
53 context->code[ShowTree] = showTree_stub;
6
3f00d95339a7 Use llrb in akasha
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
54
3f00d95339a7 Use llrb in akasha
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
55 /* definitions from llrb */
4
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 context->code[Put] = put_stub;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 context->code[Replace] = replaceNode_stub;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 context->code[Insert] = insertNode_stub;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 context->code[RotateL] = rotateLeft_stub;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 context->code[RotateR] = rotateRight_stub;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 context->code[InsertCase1] = insert1_stub;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 context->code[InsertCase2] = insert2_stub;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 context->code[InsertCase3] = insert3_stub;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 context->code[InsertCase4] = insert4_stub;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 context->code[InsertCase4_1] = insert4_1_stub;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 context->code[InsertCase4_2] = insert4_2_stub;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 context->code[InsertCase5] = insert5_stub;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 context->code[StackClear] = stackClear_stub;
6
3f00d95339a7 Use llrb in akasha
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents: 4
diff changeset
69 context->code[Exit] = exitCode;
4
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 context->heap = context->heapStart;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 context->data[Allocate] = context->heap;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 context->heap += sizeof(struct Allocate);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 context->data[Tree] = context->heap;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 context->heap += sizeof(struct Tree);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 context->data[Node] = context->heap;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 context->heap += sizeof(struct Node);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 context->dataNum = Node;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 struct Tree* tree = &context->data[Tree]->tree;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 tree->root = 0;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 tree->current = 0;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 tree->deleted = 0;
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 context->node_stack = stack_init(sizeof(struct Node*), 100);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 context->code_stack = stack_init(sizeof(enum Code), 100);
d41e349d6e22 Fix filename
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 }