Mercurial > hg > Members > Moririn
annotate src/parallel_execution/SingleLinkedStack.cbc @ 194:081607dcf893
create generate_stub.pl
author | mir3636 |
---|---|
date | Fri, 16 Dec 2016 19:40:42 +0900 |
parents | src/parallel_execution/stack.cbc@06cfc1289361 |
children | ebc13549394c |
rev | line source |
---|---|
135 | 1 #include "context.h" |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
2 #include "origin_cs.h" |
138 | 3 #include <stdio.h> |
86 | 4 |
158 | 5 typedef struct SingleLinkedStack { |
6 struct Element* top; | |
7 } SingleLinkedStack; | |
8 | |
150 | 9 Stack* createSingleLinkedStack() { |
10 struct Stack* stack = new Stack(); | |
11 struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack(); | |
12 stack->stack = singleLinkedStack; | |
132 | 13 singleLinkedStack->top = NULL; |
150 | 14 stack->push = pushSingleLinkedStack; |
15 stack->pop = popSingleLinkedStack; | |
16 stack->pop2 = pop2SingleLinkedStack; | |
17 stack->get = getSingleLinkedStack; | |
18 stack->get2 = get2SingleLinkedStack; | |
19 stack->isEmpty = isEmptySingleLinkedStack; | |
20 stack->clear = clearSingleLinkedStack; | |
21 return stack; | |
86 | 22 } |
23 | |
138 | 24 void printStack1(union Data* data) { |
25 struct Node* node = &data->element.data->node; | |
26 if (node == NULL) { | |
27 printf("NULL"); | |
28 } else { | |
29 printf("key = %d ,", node->key); | |
30 printStack1((union Data*)data->element.next); | |
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 | |
158 | 52 __code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(..., union Data*)) { |
53 union Data* data; | |
136 | 54 if (stack->top) { |
55 *data = stack->top->data; | |
56 stack->top = stack->top->next; | |
57 } else { | |
58 *data = NULL; | |
59 } | |
158 | 60 goto next(..., data); |
86 | 61 } |
62 | |
158 | 63 __code pop2SingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, union Data** data1, __code next(..., union Data**, union Data**)) { |
136 | 64 if (stack->top) { |
65 *data = stack->top->data; | |
66 stack->top = stack->top->next; | |
67 } else { | |
68 *data = NULL; | |
69 } | |
70 if (stack->top) { | |
71 *data1 = stack->top->data; | |
72 stack->top = stack->top->next; | |
73 } else { | |
74 *data1 = NULL; | |
75 } | |
158 | 76 goto next(..., data, data1); |
133 | 77 } |
78 | |
154 | 79 |
150 | 80 __code getSingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, __code next(...)) { |
141
4f6a660c14a1
stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
140
diff
changeset
|
81 if (stack->top) |
4f6a660c14a1
stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
140
diff
changeset
|
82 *data = stack->top->data; |
4f6a660c14a1
stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
140
diff
changeset
|
83 else |
4f6a660c14a1
stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
140
diff
changeset
|
84 *data = NULL; |
150 | 85 goto next(...); |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
86 } |
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
87 |
154 | 88 __code get2SingleLinkedStack(struct SingleLinkedStack* stack,..., __code next(...)) { |
89 union Data* data, *data1; | |
90 | |
136 | 91 if (stack->top) { |
166 | 92 data = stack->top->data; |
93 if (stack->top->next) { | |
94 data1 = stack->top->next->data; | |
95 } else { | |
96 data1 = NULL; | |
97 } | |
98 } else { | |
99 data = NULL; | |
100 data1 = NUll; | |
101 } | |
102 goto next(data, data1, ...); | |
103 } | |
104 | |
150 | 105 __code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) { |
133 | 106 if (stack->top) |
150 | 107 goto next(...); |
133 | 108 else |
150 | 109 goto whenEmpty(...); |
133 | 110 } |
111 | |
132 | 112 |