ADT
arm-eh
ast-experimental
enum
forall-pointer-decay
jacob/cs343-translation
new-ast-unique-expr
pthread-emulation
qualifiedEnum
|
Last change
on this file since 032fd93 was 9082e0f1, checked in by Peter A. Buhr <pabuhr@…>, 5 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 |
|
|---|
| 6 | struct Task; // node type
|
|---|
| 7 |
|
|---|
| 8 | struct TaskDL {
|
|---|
| 9 | inline Seqable;
|
|---|
| 10 | Task & task_;
|
|---|
| 11 | };
|
|---|
| 12 | void ?{}( TaskDL & this, Task & task ) with( this ) {
|
|---|
| 13 | ((Seqable &)this){};
|
|---|
| 14 | &task_ = &task; // pointer to containing node
|
|---|
| 15 | }
|
|---|
| 16 | Task & task( TaskDL & this ) with( this ) { // getter routine for containing node
|
|---|
| 17 | return task_;
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | struct Task {
|
|---|
| 21 | TaskDL clusterRef; // list of tasks on cluster
|
|---|
| 22 | TaskDL readyRef; // list of tasks on ready queue
|
|---|
| 23 | // other stuff
|
|---|
| 24 | };
|
|---|
| 25 | void ?{}( Task & this ) with( this ) {
|
|---|
| 26 | ((TaskDL &)clusterRef){ this };
|
|---|
| 27 | ((TaskDL &)readyRef){ this };
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | int 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.