Mercurial > hg > GearsTemplate
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 |
rev | line source |
---|---|
135 | 1 #include "context.h" |
86 | 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 | 4 #include <stdio.h> |
86 | 5 |
132 | 6 union Data* createSingleLinkedStack(struct Context* context) { |
135 | 7 struct Stack* stack = &ALLOCATE(context, Stack)->stack; |
8 struct SingleLinkedStack* singleLinkedStack = &ALLOCATE(context, SingleLinkedStack)->singleLinkedStack; | |
9 stack->stack = (union Data*)singleLinkedStack; | |
132 | 10 singleLinkedStack->top = NULL; |
144 | 11 stack->push = C_pushSingleLinkedStack; |
12 stack->pop = C_popSingleLinkedStack; | |
13 stack->pop2 = C_pop2SingleLinkedStack; | |
14 stack->get = C_getSingleLinkedStack; | |
15 stack->get2 = C_get2SingleLinkedStack; | |
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 | 18 return (union Data*)(stack); |
86 | 19 } |
20 | |
138 | 21 void printStack1(union Data* data) { |
22 struct Node* node = &data->element.data->node; | |
23 if (node == NULL) { | |
24 printf("NULL"); | |
25 } else { | |
26 printf("key = %d ,", node->key); | |
27 printStack1((union Data*)data->element.next); | |
28 } | |
29 } | |
30 | |
31 void printStack(union Data* data) { | |
32 printStack1(data); | |
33 printf("\n"); | |
34 } | |
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 | 46 element->next = stack->top; |
47 element->data = data; | |
48 stack->top = element; | |
49 goto meta(context, next); | |
86 | 50 } |
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 | 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 | 61 __code popSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, enum Code next) { |
136 | 62 if (stack->top) { |
63 *data = stack->top->data; | |
64 stack->top = stack->top->next; | |
65 } else { | |
66 *data = NULL; | |
67 } | |
130 | 68 goto meta(context, next); |
86 | 69 } |
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 | 76 } |
132 | 77 |
133 | 78 __code pop2SingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, union Data** data1, enum Code next) { |
136 | 79 if (stack->top) { |
80 *data = stack->top->data; | |
81 stack->top = stack->top->next; | |
82 } else { | |
83 *data = NULL; | |
84 } | |
85 if (stack->top) { | |
86 *data1 = stack->top->data; | |
87 stack->top = stack->top->next; | |
88 } else { | |
89 *data1 = NULL; | |
90 } | |
133 | 91 goto meta(context, next); |
92 } | |
93 | |
94 __code pop2SingleLinkedStack_stub(struct Context* context) { | |
136 | 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 | 100 } |
101 | |
136 | 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 | 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 | 117 __code get2SingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, union Data** data1, enum Code next) { |
136 | 118 if (stack->top) { |
119 *data = stack->top->data; | |
120 if (stack->top->next) { | |
121 *data1 = stack->top->next->data; | |
122 } else { | |
123 *data1 = NULL; | |
124 } | |
125 } else { | |
126 *data = NULL; | |
140 | 127 *data1 = NULL; |
136 | 128 } |
132 | 129 goto meta(context, next); |
130 } | |
131 | |
133 | 132 __code get2SingleLinkedStack_stub(struct Context* context) { |
136 | 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 | 138 } |
139 | |
140 __code isEmptySingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, enum Code next,enum Code whenEmpty) { | |
141 if (stack->top) | |
142 goto meta(context, next); | |
143 else | |
144 goto meta(context, whenEmpty); | |
145 } | |
146 | |
132 | 147 __code isEmptySingleLinkedStack_stub(struct Context* context) { |
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 | 152 } |
153 |