Mercurial > hg > Members > Moririn
annotate src/parallel_execution/SingleLinkedQueue.cbc @ 418:a74bec89c198
generate main
author | mir3636 |
---|---|
date | Fri, 06 Oct 2017 14:39:36 +0900 |
parents | 394e38952c80 |
children | 8d7e5d48cad3 |
rev | line source |
---|---|
266 | 1 #include "../context.h" |
2 #include <stdio.h> | |
3 | |
4 Queue* createSingleLinkedQueue(struct Context* context) { | |
280 | 5 struct Queue* queue = new Queue(); |
266 | 6 struct SingleLinkedQueue* singleLinkedQueue = new SingleLinkedQueue(); |
7 queue->queue = (union Data*)singleLinkedQueue; | |
399
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
8 singleLinkedQueue->top = new Element(); |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
9 singleLinkedQueue->last = singleLinkedQueue->top; |
266 | 10 queue->take = C_takeSingleLinkedQueue; |
11 queue->put = C_putSingleLinkedQueue; | |
12 queue->isEmpty = C_isEmptySingleLinkedQueue; | |
13 queue->clear = C_clearSingleLinkedQueue; | |
14 return queue; | |
15 } | |
16 | |
17 void printQueue1(union Data* data) { | |
18 struct Node* node = &data->Element.data->Node; | |
19 if (node == NULL) { | |
20 printf("NULL"); | |
21 } else { | |
22 printf("key = %d ,", node->key); | |
23 printQueue1((union Data*)data->Element.next); | |
24 } | |
25 } | |
26 | |
27 void printQueue(union Data* data) { | |
28 printQueue1(data); | |
29 printf("\n"); | |
30 } | |
31 | |
32 __code clearSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...)) { | |
33 queue->top = NULL; | |
34 goto next(...); | |
35 } | |
36 | |
37 __code putSingleLinkedQueue(struct SingleLinkedQueue* queue, union Data* data, __code next(...)) { | |
38 Element* element = new Element(); | |
399
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
39 element->data = data; |
266 | 40 element->next = NULL; |
399
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
41 queue->last->next = element; |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
42 queue->last = element; |
266 | 43 goto next(...); |
44 } | |
45 | |
272 | 46 __code takeSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(union Data* data, ...)) { |
399
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
47 struct Element* top = queue->top; |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
48 struct Element* nextElement = top->next; |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
49 if (queue->top == queue->last) { |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
50 data = NULL; |
266 | 51 } else { |
399
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
52 queue->top = nextElement; |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
53 data = nextElement->data; |
266 | 54 } |
55 goto next(data, ...); | |
56 } | |
57 | |
58 __code isEmptySingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...), __code whenEmpty(...)) { | |
399
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
59 if (queue->top == queue->last) |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
60 goto whenEmpty(...); |
394e38952c80
Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
280
diff
changeset
|
61 else |
266 | 62 goto next(...); |
63 } | |
64 |