#include <collections/list.hfa>




int main() {













struct req {
  int pri, rqr;
  inline struct by_pri { inline dlink(req); };
  inline struct by_rqr { inline dlink(req); };
};





// need to spice this case; can't forward declare nested struct
P9_EMBEDDED_INFUNC(req, req.by_pri)
P9_EMBEDDED_INFUNC(req, req.by_rqr)
P9_EMBEDDED_INFUNC(req.by_pri, dlink(req))
P9_EMBEDDED_INFUNC(req.by_rqr, dlink(req))





dlist(req, req.by_pri) reqs_pri_global;
dlist(req, req.by_rqr) reqs_rqr_42;
dlist(req, req.by_rqr) reqs_rqr_17;
dlist(req, req.by_rqr) reqs_rqr_99;

struct req
  r42a = {1, 42},
  r42b = {2, 42},
  r17a = {2, 17},
  r17b = {3, 17},
  r17c = {4, 17},
  r99a = {3, 99};

insert_first(reqs_pri_global, r17c);
insert_first(reqs_pri_global, r99a);
insert_first(reqs_pri_global, r17b);
insert_first(reqs_pri_global, r42b);
insert_first(reqs_pri_global, r17a);
insert_first(reqs_pri_global, r42a);

insert_first(reqs_rqr_42, r42b);
insert_first(reqs_rqr_42, r42a);

insert_first(reqs_rqr_17, r17c);
insert_first(reqs_rqr_17, r17b);
insert_first(reqs_rqr_17, r17a);

insert_first(reqs_rqr_99, r99a);








with(DLINK_VIA(req, req.by_pri)) {
    while( req & cur = reqs_pri_global`elems; cur`moveNext )
        printf("{%d %d} ", cur.pri, cur.rqr);
    printf("| ");
}

with(DLINK_VIA(req, req.by_rqr)) {
    while( req & cur = reqs_rqr_42`elems; cur`moveNext )
        printf("{%d %d} ", cur.pri, cur.rqr);
    printf("| ");
    while( req & cur = reqs_rqr_17`elems; cur`moveNext )
        printf("{%d %d} ", cur.pri, cur.rqr);
    printf("| ");
    while( req & cur = reqs_rqr_99`elems; cur`moveNext )
        printf("{%d %d} ", cur.pri, cur.rqr);
    printf("\n");
}




}
