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