#include #include #include "sequence.hfa" #include "stack.hfa" struct Task; // node type struct TaskDL { inline Seqable; Task & task_; }; void ?{}( TaskDL & this, Task & task ) with( this ) { ((Seqable &)this){}; &task_ = &task; // pointer to containing node } Task & task( TaskDL & this ) with( this ) { // getter routine for containing node return task_; } struct Task { TaskDL clusterRef; // list of tasks on cluster TaskDL readyRef; // list of tasks on ready queue // other stuff }; void ?{}( Task & this ) with( this ) { ((TaskDL &)clusterRef){ this }; ((TaskDL &)readyRef){ this }; } int main() { Sequence(TaskDL) clustList, readyList; // task lists enum { Lnth = 10 }; for ( Lnth ) { Task & task = *new(); // create task node addHead( clustList, task.clusterRef ); // insert on lists in opposite directions addTail( readyList, task.readyRef ); } SeqIter(TaskDL) iter; TaskDL & dl; sout | nlOff; for ( over( iter, clustList ); iter >> dl; ) { // print lists sout | &task( dl ); } sout | nl; for ( SeqIter(TaskDL) iter = { readyList }; iter >> dl; ) { sout | &task( dl ); } sout | nl; for ( Lnth ) { // remove nodes from clustList dropHead( clustList ); } for ( Lnth ) { // remove nodes from readyList and safe to delete nodes delete( &task( dropHead( readyList ) ) ); } // Stack(TaskDL) fredStack; // for ( Lnth ) { // Task & task = *new(); // create task node // push( fredStack, task.clusterRef ); // insert on lists in opposite directions // } }