source: libcfa/src/bits/multi_list.cfa @ 9082e0f1

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 9082e0f1 was 9082e0f1, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

add multi-list container test

  • Property mode set to 100644
File size: 1.6 KB
Line 
1#include <fstream.hfa>
2#include <stdlib.hfa>
3#include "sequence.hfa"
4#include "stack.hfa"
5
6struct Task;                                                                                    // node type
7
8struct TaskDL {
9        inline Seqable;
10        Task & task_;
11};
12void ?{}( TaskDL & this, Task & task ) with( this ) {
13        ((Seqable &)this){};
14        &task_ = &task;                                                                         // pointer to containing node
15}
16Task & task( TaskDL & this ) with( this ) {                             // getter routine for containing node
17        return task_;
18}
19
20struct Task {
21        TaskDL clusterRef;                                                                      // list of tasks on cluster
22        TaskDL readyRef;                                                                        // list of tasks on ready queue
23        // other stuff
24};
25void ?{}( Task & this ) with( this ) {
26        ((TaskDL &)clusterRef){ this };
27        ((TaskDL &)readyRef){ this };
28}
29
30int main() {
31        Sequence(TaskDL) clustList, readyList;                          // task lists
32        enum { Lnth = 10 };
33
34        for ( Lnth ) {
35                Task & task = *new();                                                   // create task node
36                addHead( clustList, task.clusterRef );                  // insert on lists in opposite directions
37                addTail( readyList, task.readyRef );
38        }
39
40        SeqIter(TaskDL) iter;
41        TaskDL & dl;
42
43        sout | nlOff;
44        for ( over( iter, clustList ); iter >> dl; ) {          // print lists
45                sout | &task( dl );
46        }
47        sout | nl;
48        for ( SeqIter(TaskDL) iter = { readyList }; iter >> dl; ) {
49                sout | &task( dl );
50        }
51        sout | nl;
52        for ( Lnth ) {                                                                          // remove nodes from clustList
53                dropHead( clustList );
54        }
55        for ( Lnth ) {                                                                          // remove nodes from readyList and safe to delete nodes
56                delete( &task( dropHead( readyList ) ) );
57        }
58
59        // Stack(TaskDL) fredStack;
60        // for ( Lnth ) {
61        //      Task & task = *new();                                                   // create task node
62        //      push( fredStack, task.clusterRef );                             // insert on lists in opposite directions
63        // }
64}
Note: See TracBrowser for help on using the repository browser.