Mercurial > hg > GearsTemplate
annotate src/parallel_execution/SingleLinkedStack.cbc @ 280:2c2e4e597eb0
generate no compile errors
author | mir3636 |
---|---|
date | Fri, 03 Feb 2017 17:47:27 +0900 |
parents | d14eb393023d |
children | 62b7dbe7f88e |
rev | line source |
---|---|
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
1 #include "../context.h" |
138 | 2 #include <stdio.h> |
86 | 3 |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
4 // typedef struct SingleLinkedStack { |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
5 // struct Element* top; |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
6 // } SingleLinkedStack; |
158 | 7 |
274 | 8 Stack* createSingleLinkedStack(struct Context* context) { |
152 | 9 struct Stack* stack = new Stack(); |
10 struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack(); | |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
11 stack->stack = (union Data*)singleLinkedStack; |
132 | 12 singleLinkedStack->top = NULL; |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
13 stack->push = C_pushSingleLinkedStack; |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
14 stack->pop = C_popSingleLinkedStack; |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
15 stack->pop2 = C_pop2SingleLinkedStack; |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
16 stack->get = C_getSingleLinkedStack; |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
17 stack->get2 = C_get2SingleLinkedStack; |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
18 stack->isEmpty = C_isEmptySingleLinkedStack; |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
19 stack->clear = C_clearSingleLinkedStack; |
152 | 20 return stack; |
86 | 21 } |
22 | |
138 | 23 void printStack1(union Data* data) { |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
24 struct Node* node = &data->Element.data->Node; |
138 | 25 if (node == NULL) { |
26 printf("NULL"); | |
27 } else { | |
28 printf("key = %d ,", node->key); | |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
253
diff
changeset
|
29 printStack1((union Data*)data->Element.next); |
138 | 30 } |
31 } | |
32 | |
33 void printStack(union Data* data) { | |
34 printStack1(data); | |
35 printf("\n"); | |
36 } | |
37 | |
152 | 38 __code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) { |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
39 stack->top = NULL; |
152 | 40 goto next(...); |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
41 } |
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
42 |
152 | 43 __code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) { |
44 Element* element = new Element(); | |
130 | 45 element->next = stack->top; |
46 element->data = data; | |
47 stack->top = element; | |
152 | 48 goto next(...); |
86 | 49 } |
50 | |
253 | 51 __code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) { |
136 | 52 if (stack->top) { |
253 | 53 data = stack->top->data; |
136 | 54 stack->top = stack->top->next; |
55 } else { | |
253 | 56 data = NULL; |
136 | 57 } |
253 | 58 goto next(data, ...); |
86 | 59 } |
60 | |
253 | 61 __code pop2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) { |
136 | 62 if (stack->top) { |
253 | 63 data = stack->top->data; |
136 | 64 stack->top = stack->top->next; |
65 } else { | |
253 | 66 data = NULL; |
136 | 67 } |
68 if (stack->top) { | |
253 | 69 data1 = stack->top->data; |
136 | 70 stack->top = stack->top->next; |
71 } else { | |
253 | 72 data1 = NULL; |
136 | 73 } |
253 | 74 goto next(data, data1, ...); |
133 | 75 } |
76 | |
154 | 77 |
253 | 78 __code getSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) { |
141
4f6a660c14a1
stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
140
diff
changeset
|
79 if (stack->top) |
253 | 80 data = stack->top->data; |
141
4f6a660c14a1
stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
140
diff
changeset
|
81 else |
253 | 82 data = NULL; |
83 goto next(data, ...); | |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
84 } |
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
85 |
253 | 86 __code get2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) { |
136 | 87 if (stack->top) { |
166 | 88 data = stack->top->data; |
89 if (stack->top->next) { | |
90 data1 = stack->top->next->data; | |
91 } else { | |
92 data1 = NULL; | |
93 } | |
94 } else { | |
95 data = NULL; | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
96 data1 = NULL; |
166 | 97 } |
98 goto next(data, data1, ...); | |
99 } | |
100 | |
152 | 101 __code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) { |
133 | 102 if (stack->top) |
152 | 103 goto next(...); |
133 | 104 else |
152 | 105 goto whenEmpty(...); |
133 | 106 } |
107 | |
132 | 108 |