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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
266
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
1 #include "../context.h"
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
2 #include <stdio.h>
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
3
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
4 Queue* createSingleLinkedQueue(struct Context* context) {
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 272
diff changeset
5 struct Queue* queue = new Queue();
266
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
6 struct SingleLinkedQueue* singleLinkedQueue = new SingleLinkedQueue();
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
10 queue->take = C_takeSingleLinkedQueue;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
11 queue->put = C_putSingleLinkedQueue;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
12 queue->isEmpty = C_isEmptySingleLinkedQueue;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
13 queue->clear = C_clearSingleLinkedQueue;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
14 return queue;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
15 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
16
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
17 void printQueue1(union Data* data) {
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
18 struct Node* node = &data->Element.data->Node;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
19 if (node == NULL) {
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
20 printf("NULL");
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
21 } else {
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
22 printf("key = %d ,", node->key);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
23 printQueue1((union Data*)data->Element.next);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
24 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
25 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
26
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
27 void printQueue(union Data* data) {
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
28 printQueue1(data);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
29 printf("\n");
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
30 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
31
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
32 __code clearSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...)) {
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
33 queue->top = NULL;
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
34 goto next(...);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
35 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
36
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
37 __code putSingleLinkedQueue(struct SingleLinkedQueue* queue, union Data* data, __code next(...)) {
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
43 goto next(...);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
44 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
45
272
mir3636
parents: 266
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
54 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
55 goto next(data, ...);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
56 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
57
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
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
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
62 goto next(...);
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
63 }
ffcd80cc3a83 create SingleLinkedQueue.cbc
mir3636
parents:
diff changeset
64