annotate src/parallel_execution/stack.cbc @ 150:7164f59660d4

create .cbc
author mir3636
date Tue, 15 Nov 2016 17:46:29 +0900
parents src/parallel_execution/stack.c@473b7d990a1f
children efef5d4df54f
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"
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
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
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
4 #include <stdio.h>
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
6 Stack* createSingleLinkedStack() {
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
7 struct Stack* stack = new Stack();
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
8 struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack();
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
9 stack->stack = singleLinkedStack;
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
10 singleLinkedStack->top = NULL;
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
11 stack->push = pushSingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
12 stack->pop = popSingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
13 stack->pop2 = pop2SingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
14 stack->get = getSingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
15 stack->get2 = get2SingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
16 stack->isEmpty = isEmptySingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
17 stack->clear = clearSingleLinkedStack;
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
18 return stack;
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
138
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
21 void printStack1(union Data* data) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
22 struct Node* node = &data->element.data->node;
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
23 if (node == NULL) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
24 printf("NULL");
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
25 } else {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
26 printf("key = %d ,", node->key);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
27 printStack1((union Data*)data->element.next);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
28 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
29 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
30
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
31 void printStack(union Data* data) {
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
32 printStack1(data);
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
33 printf("\n");
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
34 }
04a2f486a30d insert works but is not balanced
kono
parents: 136
diff changeset
35
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
36 __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
37 stack->top = NULL;
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
38 goto next(...);
145
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
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
41 __code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) {
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
42 Element* element = new Element();
130
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
43 element->next = stack->top;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
44 element->data = data;
2bb5e4f0fd35 Stackinterface
ikkun
parents: 113
diff changeset
45 stack->top = element;
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
46 goto next(...);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
49 __code popSingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, __code next(...)) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
50 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
51 *data = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
52 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
53 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
54 *data = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
55 }
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
56 goto next(...);
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
57 // goto next(data, ...);
86
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 }
e06e1a9e569e create worker
Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
60 __code pop2SingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, union Data** data1, __code next(...)) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
61 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
62 *data = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
63 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
64 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
65 *data = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
66 }
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
67 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
68 *data1 = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
69 stack->top = stack->top->next;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
70 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
71 *data1 = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
72 }
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
73 goto next(...);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
74 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
75
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
76 __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
77 if (stack->top)
4f6a660c14a1 stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
78 *data = stack->top->data;
4f6a660c14a1 stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
79 else
4f6a660c14a1 stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
80 *data = NULL;
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
81 goto next(...);
134
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
82 }
2eccf4564efe fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
83
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
84 __code get2SingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, union Data** data1, __code next(...)) {
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
85 if (stack->top) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
86 *data = stack->top->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
87 if (stack->top->next) {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
88 *data1 = stack->top->next->data;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
89 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
90 *data1 = NULL;
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
91 }
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
92 } else {
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
93 *data = NULL;
140
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 138
diff changeset
94 *data1 = NULL;
136
a747dc9d4da6 stack refactering no compile error
mir3636
parents: 135
diff changeset
95 }
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
96 goto next(...);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
97 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
98
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
99 __code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) {
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
100 if (stack->top)
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
101 goto next(...);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
102 else
150
7164f59660d4 create .cbc
mir3636
parents: 148
diff changeset
103 goto whenEmpty(...);
133
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
104 }
568730b1239e call stack interface in rb_tree
mir3636
parents: 132
diff changeset
105
132
7c309e1aea73 Code Gears stack api
one
parents: 131
diff changeset
106