where is the name of the structure to be defined, and is the type of the elements to be linked into the list. A pointer to the head of the list can later be declared as: struct HEADNAME *headp;
(The names and are user selectable.) The macro declares a structure that connects the elements in the list. The macro initializes the list referenced by The macro inserts the new element at the head of the list. The macro inserts the new element after the element The macro inserts the new element before the element The macro removes the element from the list.
LIST_INIT(&head); /* Initialize the list. */
n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ LIST_INSERT_HEAD(&head, n1, entries);
n2 = malloc(sizeof(struct entry)); /* Insert after. */ LIST_INSERT_AFTER(n1, n2, entries);
n2 = malloc(sizeof(struct entry)); /* Insert before. */ LIST_INSERT_BEFORE(n1,
n2, entries); /* Forward traversal. */
for (np = head.lh_first; np != NULL; np = np->entries.le_next) np-> ...
while (head.lh_first != NULL) /* Delete. */ LIST_REMOVE(head.lh_first, entries);
where is the name of the structure to be defined, and is the type of the elements to be linked into the tail queue. A pointer to the head of the tail queue can later be declared as: struct HEADNAME *headp;
(The names and are user selectable.) The macro declares a structure that connects the elements in the tail queue. The macro initializes the tail queue referenced by The macro inserts the new element at the head of the tail queue. The macro inserts the new element at the end of the tail queue. The macro inserts the new element after the element The macro inserts the new element before the element The macro removes the element from the tail queue.
TAILQ_INIT(&head); /* Initialize the queue. */
n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ TAILQ_INSERT_HEAD(&head, n1, entries);
n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ TAILQ_INSERT_TAIL(&head, n1, entries);
n2 = malloc(sizeof(struct entry)); /* Insert after. */ TAILQ_INSERT_AFTER(&head, n1, n2, entries);
n2 = malloc(sizeof(struct entry)); /* Insert before. */
TAILQ_INSERT_BEFORE(n1, n2, entries); /* Forward traversal. */
for (np = head.tqh_first; np != NULL; np = np->entries.tqe_next) np-> ...
/* Delete. */
while (head.tqh_first != NULL) TAILQ_REMOVE(&head, head.tqh_first, entries);
where is the name of the structure to be defined, and is the type of the elements to be linked into the circular queue. A pointer to the head of the circular queue can later be declared as: struct HEADNAME *headp;
(The names and are user selectable.) The macro declares a structure that connects the elements in the circular queue. The macro initializes the circular queue referenced by The macro inserts the new element at the head of the circular queue. The macro inserts the new element at the end of the circular queue. The macro inserts the new element after the element The macro inserts the new element before the element The macro removes the element from the circular queue.
CIRCLEQ_INIT(&head); /* Initialize the circular queue. */
n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ CIRCLEQ_INSERT_HEAD(&head, n1, entries);
n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ CIRCLEQ_INSERT_TAIL(&head, n1, entries);
n2 = malloc(sizeof(struct entry)); /* Insert after. */ CIRCLEQ_INSERT_AFTER(&head, n1, n2, entries);
n2 = malloc(sizeof(struct
entry)); /* Insert before. */ CIRCLEQ_INSERT_BEFORE(&head, n1, n2, entries);
/* Forward traversal. */
for (np = head.cqh_first; np != (void *)&head; np = np->entries.cqe_next) np->
...
/* Reverse traversal. */
for (np = head.cqh_last; np != (void *)&head; np = np->entries.cqe_prev) np->
...
/* Delete. */
while (head.cqh_first != (void *)&head) CIRCLEQ_REMOVE(&head, head.cqh_first,
entries);