Manual Pages for UNIX Darwin command on man TAILQ_ENTRY
MyWebUniversity

Manual Pages for UNIX Darwin command on man TAILQ_ENTRY

QUEUE(3) BSD Library Functions Manual QUEUE(3)

NAME

LLIISSTTEENNTTRRYY, LLIISSTTHHEEAADD, LLIISSTTIINNIITT, LLIISSTTIINNSSEERRTTAAFFTTEERR, LLIISSTTIINNSSEERRTTBBEEFFOORREE, LLIISSTTIINNSSEERRTTHHEEAADD, LLIISSTTRREEMMOOVVEE, TTAAIILLQQEENNTTRRYY, TTAAIILLQQHHEEAADD, TTAAIILLQQIINNIITT, TTAAIILLQQIINNSSEERRTTAAFFTTEERR, TTAAIILLQQIINNSSEERRTTBBEEFFOORREE, TTAAIILLQQIINNSSEERRTTHHEEAADD, TTAAIILLQQIINNSSEERRTTTTAAIILL, TTAAIILLQQRREEMMOOVVEE, CCIIRRCCLLEEQQEENNTTRRYY, CCIIRRCCLLEEQQHHEEAADD, CCIIRRCCLLEEQQIINNIITT, CCIIRRCCLLEEQQIINNSSEERRTTAAFFTTEERR, CCIIRRCCLLEEQQIINNSSEERRTTBBEEFFOORREE,

CCIIRRCCLLEEQQIINNSSEERRTTHHEEAADD, CCIIRRCCLLEEQQIINNSSEERRTTTTAAIILL, CCIIRRCCLLEEQQRREEMMOOVVEE - implementa-

tions of lists, tail queues, and circular queues

SYNOPSIS

##iinncclluuddee <>

LLIISSTTEENNTTRRYY(TYPE);

LLIISSTTHHEEAADD(HEADNAME, TYPE);

LLIISSTTIINNIITT(LISTHEAD *head);

LLIISSTTIINNSSEERRTTAAFFTTEERR(TYPE *listelm, TYPE *elm, LISTENTRY NAME);

LLIISSTTIINNSSEERRTTBBEEFFOORREE(TYPE *listelm, TYPE *elm, LISTENTRY NAME);

LLIISSTTIINNSSEERRTTHHEEAADD(LISTHEAD *head, TYPE *elm, LISTENTRY NAME);

LLIISSTTRREEMMOOVVEE(TYPE *elm, LISTENTRY NAME);

TTAAIILLQQEENNTTRRYY(TYPE);

TTAAIILLQQHHEEAADD(HEADNAME, TYPE);

TTAAIILLQQIINNIITT(TAILQHEAD *head); TTAAIILLQQIINNSSEERRTTAAFFTTEERR(TAILQHEAD *head, TYPE *listelm, TYPE *elm,

TAILQENTRY NAME);

TTAAIILLQQIINNSSEERRTTBBEEFFOORREE(TYPE *listelm, TYPE *elm, TAILQENTRY NAME);

TTAAIILLQQIINNSSEERRTTHHEEAADD(TAILQHEAD *head, TYPE *elm, TAILQENTRY NAME);

TTAAIILLQQIINNSSEERRTTTTAAIILL(TAILQHEAD *head, TYPE *elm, TAILQENTRY NAME);

TTAAIILLQQRREEMMOOVVEE(TAILQHEAD *head, TYPE *elm, TAILQENTRY NAME);

CCIIRRCCLLEEQQEENNTTRRYY(TYPE);

CCIIRRCCLLEEQQHHEEAADD(HEADNAME, TYPE);

CCIIRRCCLLEEQQIINNIITT(CIRCLEQHEAD *head); CCIIRRCCLLEEQQIINNSSEERRTTAAFFTTEERR(CIRCLEQHEAD *head, TYPE *listelm, TYPE *elm,

CIRCLEQENTRY NAME);

CCIIRRCCLLEEQQIINNSSEERRTTBBEEFFOORREE(CIRCLEQHEAD *head, TYPE *listelm, TYPE *elm,

CIRCLEQENTRY NAME);

CCIIRRCCLLEEQQIINNSSEERRTTHHEEAADD(CIRCLEQHEAD *head, TYPE *elm, CIRCLEQENTRY NAME);

CCIIRRCCLLEEQQIINNSSEERRTTTTAAIILL(CIRCLEQHEAD *head, TYPE *elm, CIRCLEQENTRY NAME);

CCIIRRCCLLEEQQRREEMMOOVVEE(CIRCLEQHEAD *head, TYPE *elm, CIRCLEQENTRY NAME);

DESCRIPTION

These macros define and operate on three types of data structures: lists,

tail queues, and circular queues. All three structures support the fol-

lowing functionality: 1. Insertion of a new entry at the head of the list. 2. Insertion of a new entry before or after any element in the list. 3. Removal of any entry in the list. 4. Forward traversal through the list. Lists are the simplest of the three data structures and support only the above functionality. Tail queues add the following functionality: 1. Entries can be added at the end of a list. However: 1. All list insertions and removals, except insertion before another element, must specify the head of the list. 2. Each head entry requires two pointers rather than one.

3. Code size is about 15% greater and operations run about 20%

slower than lists. Circular queues add the following functionality: 1. Entries can be added at the end of a list. 2. They may be traversed backwards, from tail to head. However: 1. All list insertions and removals must specify the head of the list. 2. Each head entry requires two pointers rather than one. 3. The termination condition for traversal is more complex.

4. Code size is about 40% greater and operations run about 45%

slower than lists. In the macro definitions, TYPE is the name of a user defined structure, that must contain a field of type LISTENTRY, TAILQENTRY, or

CIRCLEQENTRY, named NAME. The argument HEADNAME is the name of a user

defined structure that must be declared using the macros LISTHEAD,

TAILQHEAD, or CIRCLEQHEAD. See the examples below for further explana-

tion of how these macros are used. LLIISSTTSS A list is headed by a structure defined by the LLIISSTTHHEEAADD macro. This structure contains a single pointer to the first element on the list. The elements are doubly linked so that an arbitrary element can be removed without traversing the list. New elements can be added to the list after an existing element, before an existing element, or at the head of the list. A LISTHEAD structure is declared as follows:

LISTHEAD(HEADNAME, TYPE) head;

where HEADNAME is the name of the structure to be defined, and TYPE 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 head and headp are user selectable.) The macro LLIISSTTEENNTTRRYY declares a structure that connects the elements in the list. The macro LLIISSTTIINNIITT initializes the list referenced by head. The macro LLIISSTTIINNSSEERRTTHHEEAADD inserts the new element elm at the head of the list. The macro LLIISSTTIINNSSEERRTTAAFFTTEERR inserts the new element elm after the element listelm.

The macro LLIISSTTIINNSSEERRTTBBEEFFOORREE inserts the new element elm before the ele-

ment listelm. The macro LLIISSTTRREEMMOOVVEE removes the element elm from the list. LLIISSTT EEXXAAMMPPLLEE LISTHEAD(listhead, entry) head; struct listhead *headp; /* List head. */ struct entry { ... LISTENTRY(entry) entries; /* List. */ ... } *n1, *n2, *np; LISTINIT(&head); /* Initialize the list. */ n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ LISTINSERTHEAD(&head, n1, entries); n2 = malloc(sizeof(struct entry)); /* Insert after. */ LISTINSERTAFTER(n1, n2, entries); n2 = malloc(sizeof(struct entry)); /* Insert before. */ LISTINSERTBEFORE(n1, n2, entries); /* Forward traversal. */

for (np = head.lhfirst; np != NULL; np = np->entries.lenext)

np-> ...

while (head.lhfirst != NULL) /* Delete. */ LISTREMOVE(head.lhfirst, entries); TTAAIILL QQUUEEUUEESS A tail queue is headed by a structure defined by the TTAAIILLQQHHEEAADD macro. This structure contains a pair of pointers, one to the first element in the tail queue and the other to the last element in the tail queue. The elements are doubly linked so that an arbitrary element can be removed without traversing the tail queue. New elements can be added to the queue after an existing element, before an existing element, at the head of the queue, or at the end the queue. A TAILQHEAD structure is declared as follows:

TAILQHEAD(HEADNAME, TYPE) head;

where HEADNAME is the name of the structure to be defined, and TYPE 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 head and headp are user selectable.) The macro TTAAIILLQQEENNTTRRYY declares a structure that connects the elements in the tail queue. The macro TTAAIILLQQIINNIITT initializes the tail queue referenced by head. The macro TTAAIILLQQIINNSSEERRTTHHEEAADD inserts the new element elm at the head of the tail queue. The macro TTAAIILLQQIINNSSEERRTTTTAAIILL inserts the new element elm at the end of the tail queue.

The macro TTAAIILLQQIINNSSEERRTTAAFFTTEERR inserts the new element elm after the ele-

ment listelm.

The macro TTAAIILLQQIINNSSEERRTTBBEEFFOORREE inserts the new element elm before the ele-

ment listelm. The macro TTAAIILLQQRREEMMOOVVEE removes the element elm from the tail queue. TTAAIILL QQUUEEUUEE EEXXAAMMPPLLEE TAILQHEAD(tailhead, entry) head; struct tailhead *headp; /* Tail queue head. */ struct entry { ... TAILQENTRY(entry) entries; /* Tail queue. */ ... } *n1, *n2, *np; TAILQINIT(&head); /* Initialize the queue. */ n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ TAILQINSERTHEAD(&head, n1, entries); n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ TAILQINSERTTAIL(&head, n1, entries); n2 = malloc(sizeof(struct entry)); /* Insert after. */ TAILQINSERTAFTER(&head, n1, n2, entries); n2 = malloc(sizeof(struct entry)); /* Insert before. */ TAILQINSERTBEFORE(n1, n2, entries); /* Forward traversal. */

for (np = head.tqhfirst; np != NULL; np = np->entries.tqenext)

np-> ...

/* Delete. */ while (head.tqhfirst != NULL) TAILQREMOVE(&head, head.tqhfirst, entries); CCIIRRCCUULLAARR QQUUEEUUEESS A circular queue is headed by a structure defined by the CCIIRRCCLLEEQQHHEEAADD

macro. This structure contains a pair of pointers, one to the first ele-

ment in the circular queue and the other to the last element in the cir-

cular queue. The elements are doubly linked so that an arbitrary element can be removed without traversing the queue. New elements can be added to the queue after an existing element, before an existing element, at

the head of the queue, or at the end of the queue. A CIRCLEQHEAD struc-

ture is declared as follows:

CIRCLEQHEAD(HEADNAME, TYPE) head;

where HEADNAME is the name of the structure to be defined, and TYPE 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 head and headp are user selectable.) The macro CCIIRRCCLLEEQQEENNTTRRYY declares a structure that connects the elements in the circular queue. The macro CCIIRRCCLLEEQQIINNIITT initializes the circular queue referenced by head. The macro CCIIRRCCLLEEQQIINNSSEERRTTHHEEAADD inserts the new element elm at the head of the circular queue. The macro CCIIRRCCLLEEQQIINNSSEERRTTTTAAIILL inserts the new element elm at the end of the circular queue.

The macro CCIIRRCCLLEEQQIINNSSEERRTTAAFFTTEERR inserts the new element elm after the ele-

ment listelm. The macro CCIIRRCCLLEEQQIINNSSEERRTTBBEEFFOORREE inserts the new element elm before the element listelm. The macro CCIIRRCCLLEEQQRREEMMOOVVEE removes the element elm from the circular queue. CCIIRRCCUULLAARR QQUUEEUUEE EEXXAAMMPPLLEE CIRCLEQHEAD(circleq, entry) head; struct circleq *headp; /* Circular queue head. */ struct entry { ... CIRCLEQENTRY entries; /* Circular queue. */ ... } *n1, *n2, *np; CIRCLEQINIT(&head); /* Initialize the circular queue. */ n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ CIRCLEQINSERTHEAD(&head, n1, entries); n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ CIRCLEQINSERTTAIL(&head, n1, entries); n2 = malloc(sizeof(struct entry)); /* Insert after. */ CIRCLEQINSERTAFTER(&head, n1, n2, entries); n2 = malloc(sizeof(struct entry)); /* Insert before. */ CIRCLEQINSERTBEFORE(&head, n1, n2, entries); /* Forward traversal. */

for (np = head.cqhfirst; np != (void *)&head; np = np->entries.cqenext)

np-> ...

/* Reverse traversal. */

for (np = head.cqhlast; np != (void *)&head; np = np->entries.cqeprev)

np-> ...

/* Delete. */ while (head.cqhfirst != (void *)&head) CIRCLEQREMOVE(&head, head.cqhfirst, entries); HISTORY The qquueeuuee functions first appeared in 4.4BSD. 4th Berkeley Distribution December 13, 1993 4th Berkeley Distribution




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™