Search code examples
clinked-listqueuedynamic-memory-allocationabstract-data-type

queue.h: how to create list of lists / queue of queues / similar combinations?


Man page of BSD's queue.h clearly shows how to create a single-/double-linked list/tail queue, but I can't get how to create, for example, list of lists or queue of queues? Especially, how to deal with declaration(s) and initialization(s) of slave query?

What did I tried:

//element of slave queue
struct slaveentry {
    STAILQ_ENTRY(slaveentry) pts;   //pointers
    /*data here*/
    } *selt;                        //element of queue

//element of master queue
struct masterentry {
    STAILQ_ENTRY(masterentry) pts;  //pointers
    struct slavehead *slave;        //pointer to slave queue head
    /*data here*/
    } *melt;                        //element of queue

//initialization of sturctures
STAILQ_HEAD(masterhead, masterentry) big_queue = STAILQ_HEAD_INITIALIZER(big_queue);
STAILQ_INIT(&big_queue);

//what's next? I don't know, maybe some sort of the following
STAILQ_HEAD(slavehead, slaveentry) small_queue = STAILQ_HEAD_INITIALIZER(small_queue);
STAILQ_INIT(&small_queue);

Solution

  • If you are interested in solution, you can see it here: https://gist.github.com/postboy/fb825b9fe813a0a18d04ef4cdf2ac7a0

    I had to spent some time before I understood how to deal with this problem, so this question appeared here several days ago.