Mercurial > hg > Members > Moririn
annotate src/parallel_execution/stack.c @ 138:04a2f486a30d
insert works but is not balanced
author | kono |
---|---|
date | Tue, 08 Nov 2016 19:39:40 +0900 (2016-11-08) |
parents | a747dc9d4da6 |
children | f31b4e4bf4bb |
rev | line source |
---|---|
135 | 1 #include "context.h" |
86 | 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 | 4 #include <stdio.h> |
86 | 5 |
132 | 6 union Data* createSingleLinkedStack(struct Context* context) { |
135 | 7 struct Stack* stack = &ALLOCATE(context, Stack)->stack; |
8 struct SingleLinkedStack* singleLinkedStack = &ALLOCATE(context, SingleLinkedStack)->singleLinkedStack; | |
9 stack->stack = (union Data*)singleLinkedStack; | |
132 | 10 singleLinkedStack->top = NULL; |
11 stack->push = PushSingleLinkedStack; | |
12 stack->pop = PopSingleLinkedStack; | |
133 | 13 stack->pop2 = Pop2SingleLinkedStack; |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
14 stack->get = GetSingleLinkedStack; |
133 | 15 stack->get2 = Get2SingleLinkedStack; |
16 stack->isEmpty = IsEmptySingleLinkedStack; | |
135 | 17 return (union Data*)(stack); |
86 | 18 } |
19 | |
138 | 20 void printStack1(union Data* data) { |
21 struct Node* node = &data->element.data->node; | |
22 if (node == NULL) { | |
23 printf("NULL"); | |
24 } else { | |
25 printf("key = %d ,", node->key); | |
26 printStack1((union Data*)data->element.next); | |
27 } | |
28 } | |
29 | |
30 void printStack(union Data* data) { | |
31 printStack1(data); | |
32 printf("\n"); | |
33 } | |
34 | |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
35 __code pushSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, struct Element* element, union Data* data, enum Code next) { |
130 | 36 element->next = stack->top; |
37 element->data = data; | |
38 stack->top = element; | |
39 goto meta(context, next); | |
86 | 40 } |
41 | |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
42 __code pushSingleLinkedStack_stub(struct Context* context) { |
135 | 43 struct Element* element = &ALLOCATE(context, Element)->element; |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
44 goto pushSingleLinkedStack(context, |
136 | 45 (struct SingleLinkedStack *)&context->data[Stack]->stack.stack, |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
46 element, |
136 | 47 context->data[Stack]->stack.data, |
48 context->data[Stack]->stack.next); | |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
49 } |
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
50 |
132 | 51 __code popSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, enum Code next) { |
136 | 52 if (stack->top) { |
53 *data = stack->top->data; | |
54 stack->top = stack->top->next; | |
55 } else { | |
56 *data = NULL; | |
57 } | |
130 | 58 goto meta(context, next); |
86 | 59 } |
60 | |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
61 __code popSingleLinkedStack_stub(struct Context* context) { |
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
62 goto popSingleLinkedStack(context, |
136 | 63 (struct SingleLinkedStack *)context->data[Stack]->stack.stack, |
132 | 64 &context->data[Stack]->stack.data, |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
65 context->data[Stack]->stack.next); |
86 | 66 } |
132 | 67 |
133 | 68 __code pop2SingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, union Data** data1, enum Code next) { |
136 | 69 if (stack->top) { |
70 *data = stack->top->data; | |
71 stack->top = stack->top->next; | |
72 } else { | |
73 *data = NULL; | |
74 } | |
75 if (stack->top) { | |
76 *data1 = stack->top->data; | |
77 stack->top = stack->top->next; | |
78 } else { | |
79 *data1 = NULL; | |
80 } | |
133 | 81 goto meta(context, next); |
82 } | |
83 | |
84 __code pop2SingleLinkedStack_stub(struct Context* context) { | |
136 | 85 goto pop2SingleLinkedStack(context, |
86 (struct SingleLinkedStack *)context->data[Stack]->stack.stack, | |
133 | 87 &context->data[Stack]->stack.data, |
88 &context->data[Stack]->stack.data1, | |
89 context->data[Stack]->stack.next); | |
90 } | |
91 | |
136 | 92 __code getSingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, enum Code next) { |
93 *data = stack->top->data; | |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
94 goto meta(context, next); |
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
95 } |
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
96 |
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
97 __code getSingleLinkedStack_stub(struct Context* context) { |
136 | 98 goto getSingleLinkedStack(context, |
99 (struct SingleLinkedStack *)context->data[Stack]->stack.stack, | |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
100 &context->data[Stack]->stack.data, |
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
101 context->data[Stack]->stack.next); |
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
102 } |
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
103 |
133 | 104 __code get2SingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, union Data** data, union Data** data1, enum Code next) { |
136 | 105 if (stack->top) { |
106 *data = stack->top->data; | |
107 if (stack->top->next) { | |
108 *data1 = stack->top->next->data; | |
109 } else { | |
110 *data1 = NULL; | |
111 } | |
112 } else { | |
113 *data = NULL; | |
114 } | |
132 | 115 goto meta(context, next); |
116 } | |
117 | |
133 | 118 __code get2SingleLinkedStack_stub(struct Context* context) { |
136 | 119 goto get2SingleLinkedStack(context, |
120 (struct SingleLinkedStack *)context->data[Stack]->stack.stack, | |
133 | 121 &context->data[Stack]->stack.data, |
122 &context->data[Stack]->stack.data1, | |
123 context->data[Stack]->stack.next); | |
124 } | |
125 | |
126 __code isEmptySingleLinkedStack(struct Context* context, struct SingleLinkedStack* stack, enum Code next,enum Code whenEmpty) { | |
127 if (stack->top) | |
128 goto meta(context, next); | |
129 else | |
130 goto meta(context, whenEmpty); | |
131 } | |
132 | |
132 | 133 __code isEmptySingleLinkedStack_stub(struct Context* context) { |
134 goto isEmptySingleLinkedStack(context, | |
136 | 135 (struct SingleLinkedStack *)context->data[Stack]->stack.stack, |
133 | 136 context->data[Stack]->stack.next, |
137 context->data[Stack]->stack.whenEmpty); | |
132 | 138 } |
139 |