annotate src/parallel_execution/stack.c @ 170:ee7134f3bef1

Fix
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Tue, 22 Nov 2016 10:36:45 +0900
parents 473b7d990a1f
children 119c035e0e36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
135
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1 #include "context.h"
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include "stack.h"
131
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
3 #include "origin_cs.h"
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
4 #include <stdio.h>
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
6 union Data* createSingleLinkedStack(struct Context* context) {
135
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
7 struct Stack* stack = &ALLOCATE(context, Stack)->stack;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
8 struct SingleLinkedStack* singleLinkedStack = &ALLOCATE(context, SingleLinkedStack)->singleLinkedStack;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
9 stack->stack = (union Data*)singleLinkedStack;
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
10 singleLinkedStack->top = NULL;
144
d529c024e5a5 name fixes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
11 stack->push = C_pushSingleLinkedStack;
d529c024e5a5 name fixes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
12 stack->pop = C_popSingleLinkedStack;
d529c024e5a5 name fixes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
13 stack->pop2 = C_pop2SingleLinkedStack;
d529c024e5a5 name fixes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
14 stack->get = C_getSingleLinkedStack;
d529c024e5a5 name fixes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
15 stack->get2 = C_get2SingleLinkedStack;
d529c024e5a5 name fixes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 141
diff changeset
16 stack->isEmpty = C_isEmptySingleLinkedStack;
145
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
17 stack->clear = C_clearSingleLinkedStack;
135
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
18 return (union Data*)(stack);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
21 void printStack1(union Data* data) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
22 struct Node* node = &data->element.data->node;
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
23 if (node == NULL) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
24 printf("NULL");
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
25 } else {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
26 printf("key = %d ,", node->key);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
27 printStack1((union Data*)data->element.next);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
28 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
29 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
30
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
31 void printStack(union Data* data) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
32 printStack1(data);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
33 printf("\n");
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
34 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
35
145
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
36 __code clearSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack,enum Code next) {
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
37 stack->top = NULL;
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
38 goto meta(context, next);
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
39 }
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
40
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
41 __code clearSingleLinkedStack_stub(struct Context* context) {
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
42 goto clearSingleLinkedStack(context, (struct SingleLinkedStack *)context->data[D_Stack]->stack.stack->stack.stack, context->data[D_Stack]->stack.next);
145
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
43 }
cc071cf1ba85 add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
44
131
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
45 __code pushSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, struct Element* element, union Data* data, enum Code next) {
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 116
diff changeset
46 element->next = stack->top;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 116
diff changeset
47 element->data = data;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 116
diff changeset
48 stack->top = element;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 116
diff changeset
49 goto meta(context, next);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
131
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
52 __code pushSingleLinkedStack_stub(struct Context* context) {
135
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
53 struct Element* element = &ALLOCATE(context, Element)->element;
131
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
54 goto pushSingleLinkedStack(context,
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
55 (struct SingleLinkedStack *)context->data[D_Stack]->stack.stack->stack.stack,
131
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
56 element,
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
57 context->data[D_Stack]->stack.data,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
58 context->data[D_Stack]->stack.next);
131
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
59 }
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
60
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
61 __code popSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, enum Code next) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
62 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
63 *data = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
64 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
65 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
66 *data = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
67 }
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 116
diff changeset
68 goto meta(context, next);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
131
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
71 __code popSingleLinkedStack_stub(struct Context* context) {
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
72 goto popSingleLinkedStack(context,
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
73 (struct SingleLinkedStack *)context->data[D_Stack]->stack.stack->stack.stack,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
74 &context->data[D_Stack]->stack.data,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
75 context->data[D_Stack]->stack.next);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 }
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
77
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
78 __code pop2SingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, union Data** data1, enum Code next) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
79 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
80 *data = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
81 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
82 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
83 *data = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
84 }
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
85 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
86 *data1 = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
87 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
88 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
89 *data1 = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
90 }
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
91 goto meta(context, next);
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
92 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
93
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
94 __code pop2SingleLinkedStack_stub(struct Context* context) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
95 goto pop2SingleLinkedStack(context,
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
96 (struct SingleLinkedStack *)context->data[D_Stack]->stack.stack->stack.stack,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
97 &context->data[D_Stack]->stack.data,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
98 &context->data[D_Stack]->stack.data1,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
99 context->data[D_Stack]->stack.next);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
100 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
101
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
102 __code getSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, enum Code next) {
141
4f6a660c14a1 stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
103 if (stack->top)
4f6a660c14a1 stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
104 *data = stack->top->data;
4f6a660c14a1 stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
105 else
4f6a660c14a1 stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
106 *data = NULL;
134
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
107 goto meta(context, next);
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
108 }
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
109
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
110 __code getSingleLinkedStack_stub(struct Context* context) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
111 goto getSingleLinkedStack(context,
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
112 (struct SingleLinkedStack *)context->data[D_Stack]->stack.stack->stack.stack,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
113 &context->data[D_Stack]->stack.data,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
114 context->data[D_Stack]->stack.next);
134
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
115 }
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
116
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
117 __code get2SingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, union Data** data1, enum Code next) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
118 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
119 *data = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
120 if (stack->top->next) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
121 *data1 = stack->top->next->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
122 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
123 *data1 = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
124 }
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
125 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
126 *data = NULL;
140
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
127 *data1 = NULL;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
128 }
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
129 goto meta(context, next);
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
130 }
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
131
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
132 __code get2SingleLinkedStack_stub(struct Context* context) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
133 goto get2SingleLinkedStack(context,
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
134 (struct SingleLinkedStack *)context->data[D_Stack]->stack.stack->stack.stack,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
135 &context->data[D_Stack]->stack.data,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
136 &context->data[D_Stack]->stack.data1,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
137 context->data[D_Stack]->stack.next);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
138 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
139
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
140 __code isEmptySingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, enum Code next,enum Code whenEmpty) {
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
141 if (stack->top)
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
142 goto meta(context, next);
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
143 else
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
144 goto meta(context, whenEmpty);
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
145 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
146
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
147 __code isEmptySingleLinkedStack_stub(struct Context* context) {
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
148 goto isEmptySingleLinkedStack(context,
148
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
149 (struct SingleLinkedStack *)context->data[D_Stack]->stack.stack->stack.stack,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
150 context->data[D_Stack]->stack.next,
473b7d990a1f fix data gears type enum
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
151 context->data[D_Stack]->stack.whenEmpty);
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
152 }
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
153