annotate src/parallel_execution/stack.c @ 140:f31b4e4bf4bb

fixes
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 09 Nov 2016 13:26:53 +0900
parents 04a2f486a30d
children 4f6a660c14a1
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;
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
11 stack->push = PushSingleLinkedStack;
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
12 stack->pop = PopSingleLinkedStack;
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
13 stack->pop2 = Pop2SingleLinkedStack;
134
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
14 stack->get = GetSingleLinkedStack;
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
15 stack->get2 = Get2SingleLinkedStack;
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
16 stack->isEmpty = IsEmptySingleLinkedStack;
135
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
17 return (union Data*)(stack);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
20 void printStack1(union Data* data) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
21 struct Node* node = &data->element.data->node;
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
22 if (node == NULL) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
23 printf("NULL");
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
24 } else {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
25 printf("key = %d ,", node->key);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
26 printStack1((union Data*)data->element.next);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
27 }
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 void printStack(union Data* data) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
31 printStack1(data);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
32 printf("\n");
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
33 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
34
131
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
35 __code pushSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, struct Element* element, union Data* data, enum Code next) {
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
36 element->next = stack->top;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
37 element->data = data;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
38 stack->top = element;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
39 goto meta(context, next);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
131
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
42 __code pushSingleLinkedStack_stub(struct Context* context) {
135
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
43 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
44 goto pushSingleLinkedStack(context,
140
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
45 (struct SingleLinkedStack *)context->data[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
46 element,
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
47 context->data[Stack]->stack.data,
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
48 context->data[Stack]->stack.next);
131
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
49 }
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
50
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
51 __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
52 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
53 *data = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
54 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
55 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
56 *data = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
57 }
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
58 goto meta(context, next);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60
131
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
61 __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
62 goto popSingleLinkedStack(context,
140
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
63 (struct SingleLinkedStack *)context->data[Stack]->stack.stack->stack.stack,
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
64 &context->data[Stack]->stack.data,
131
a4507906938c Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
65 context->data[Stack]->stack.next);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 }
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
67
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
68 __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
69 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
70 *data = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
71 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
72 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
73 *data = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
74 }
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
75 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
76 *data1 = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
77 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
78 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
79 *data1 = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
80 }
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
81 goto meta(context, next);
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
82 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
83
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
84 __code pop2SingleLinkedStack_stub(struct Context* context) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
85 goto pop2SingleLinkedStack(context,
140
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
86 (struct SingleLinkedStack *)context->data[Stack]->stack.stack->stack.stack,
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
87 &context->data[Stack]->stack.data,
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
88 &context->data[Stack]->stack.data1,
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
89 context->data[Stack]->stack.next);
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
90 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
91
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
92 __code getSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, enum Code next) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
93 *data = stack->top->data;
134
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
94 goto meta(context, next);
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
95 }
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
96
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
97 __code getSingleLinkedStack_stub(struct Context* context) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
98 goto getSingleLinkedStack(context,
140
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
99 (struct SingleLinkedStack *)context->data[Stack]->stack.stack->stack.stack,
134
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
100 &context->data[Stack]->stack.data,
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
101 context->data[Stack]->stack.next);
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
102 }
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
103
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
104 __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
105 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
106 *data = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
107 if (stack->top->next) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
108 *data1 = stack->top->next->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
109 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
110 *data1 = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
111 }
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
112 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
113 *data = NULL;
140
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
114 *data1 = NULL;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
115 }
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
116 goto meta(context, next);
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
117 }
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
118
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
119 __code get2SingleLinkedStack_stub(struct Context* context) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
120 goto get2SingleLinkedStack(context,
140
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
121 (struct SingleLinkedStack *)context->data[Stack]->stack.stack->stack.stack,
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
122 &context->data[Stack]->stack.data,
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
123 &context->data[Stack]->stack.data1,
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
124 context->data[Stack]->stack.next);
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
125 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
126
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
127 __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
128 if (stack->top)
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
129 goto meta(context, next);
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
130 else
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
131 goto meta(context, whenEmpty);
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
132 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
133
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
134 __code isEmptySingleLinkedStack_stub(struct Context* context) {
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
135 goto isEmptySingleLinkedStack(context,
140
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
136 (struct SingleLinkedStack *)context->data[Stack]->stack.stack->stack.stack,
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
137 context->data[Stack]->stack.next,
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
138 context->data[Stack]->stack.whenEmpty);
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
139 }
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
140