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
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"
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
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
3 #include <stdio.h>
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
158
3fdb3334c7a9 fix stack.cbc
mir3636
parents: 154
diff changeset
5 typedef struct SingleLinkedStack {
3fdb3334c7a9 fix stack.cbc
mir3636
parents: 154
diff changeset
6 struct Element* top;
3fdb3334c7a9 fix stack.cbc
mir3636
parents: 154
diff changeset
7 } SingleLinkedStack;
3fdb3334c7a9 fix stack.cbc
mir3636
parents: 154
diff changeset
8
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
9 Stack* createSingleLinkedStack() {
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
10 struct Stack* stack = new Stack();
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
11 struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack();
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
12 stack->stack = singleLinkedStack;
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
13 singleLinkedStack->top = NULL;
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
14 stack->push = pushSingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
15 stack->pop = popSingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
16 stack->pop2 = pop2SingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
17 stack->get = getSingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
18 stack->get2 = get2SingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
19 stack->isEmpty = isEmptySingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
20 stack->clear = clearSingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
21 return stack;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
24 void printStack1(union Data* data) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
25 struct Node* node = &data->element.data->node;
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
26 if (node == NULL) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
27 printf("NULL");
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
28 } else {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
29 printf("key = %d ,", node->key);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
30 printStack1((union Data*)data->element.next);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
31 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
32 }
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 void printStack(union Data* data) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
35 printStack1(data);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
36 printf("\n");
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
37 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
38
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
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
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
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
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
44 __code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) {
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
45 Element* element = new Element();
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
46 element->next = stack->top;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
47 element->data = data;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
48 stack->top = element;
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
49 goto next(...);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
158
3fdb3334c7a9 fix stack.cbc
mir3636
parents: 154
diff changeset
52 __code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(..., union Data*)) {
3fdb3334c7a9 fix stack.cbc
mir3636
parents: 154
diff changeset
53 union Data* data;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
54 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
55 *data = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
56 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
57 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
58 *data = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
59 }
158
3fdb3334c7a9 fix stack.cbc
mir3636
parents: 154
diff changeset
60 goto next(..., data);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
158
3fdb3334c7a9 fix stack.cbc
mir3636
parents: 154
diff changeset
63 __code pop2SingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, union Data** data1, __code next(..., union Data**, union Data**)) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
64 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
65 *data = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
66 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
67 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
68 *data = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
69 }
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
70 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
71 *data1 = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
72 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
73 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
74 *data1 = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
75 }
158
3fdb3334c7a9 fix stack.cbc
mir3636
parents: 154
diff changeset
76 goto next(..., data, data1);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
77 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
78
154
efef5d4df54f Add normal level and agda code
atton
parents: 150
diff changeset
79
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
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
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
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
efef5d4df54f Add normal level and agda code
atton
parents: 150
diff changeset
88 __code get2SingleLinkedStack(struct SingleLinkedStack* stack,..., __code next(...)) {
efef5d4df54f Add normal level and agda code
atton
parents: 150
diff changeset
89 union Data* data, *data1;
efef5d4df54f Add normal level and agda code
atton
parents: 150
diff changeset
90
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
91 if (stack->top) {
166
mir3636
parents: 160
diff changeset
92 data = stack->top->data;
mir3636
parents: 160
diff changeset
93 if (stack->top->next) {
mir3636
parents: 160
diff changeset
94 data1 = stack->top->next->data;
mir3636
parents: 160
diff changeset
95 } else {
mir3636
parents: 160
diff changeset
96 data1 = NULL;
mir3636
parents: 160
diff changeset
97 }
mir3636
parents: 160
diff changeset
98 } else {
mir3636
parents: 160
diff changeset
99 data = NULL;
mir3636
parents: 160
diff changeset
100 data1 = NUll;
mir3636
parents: 160
diff changeset
101 }
mir3636
parents: 160
diff changeset
102 goto next(data, data1, ...);
mir3636
parents: 160
diff changeset
103 }
mir3636
parents: 160
diff changeset
104
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
105 __code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) {
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
106 if (stack->top)
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
107 goto next(...);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
108 else
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
109 goto whenEmpty(...);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
110 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
111
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
112