2 .\" The Regents of the University of California. All rights reserved.
3 .\" and Copyright (c) 2020 by Alejandro Colomar <colomar.6.4.3@gmail.com>
5 .\" %%%LICENSE_START(BSD_3_CLAUSE_UCB)
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .TH QUEUE 7 2021-03-22 "GNU" "Linux Programmer's Manual"
34 queue \- implementations of linked lists and queues
38 header file provides a set of macros that
39 define and operate on the following data structures:
41 singly linked lists (SLIST)
43 doubly linked lists (LIST)
45 singly linked tail queues (STAILQ)
47 doubly linked tail queues (TAILQ)
49 doubly linked circular queues (CIRCLEQ)
51 All structures support the following functionality:
53 Insertion of a new entry at the head of the list.
55 Insertion of a new entry after any element in the list.
57 O(1) removal of an entry from the head of the list.
59 Forward traversal through the list.
61 .\" Swapping the contents of two lists.
63 Code size and execution time
64 depend on the complexity of the data structure being used,
65 so programmers should take care to choose the appropriate one.
66 .SS Singly linked lists (SLIST)
67 Singly linked lists are the simplest
68 and support only the above functionality.
69 Singly linked lists are ideal for applications with
70 large datasets and few or no removals,
71 or for implementing a LIFO queue.
72 Singly linked lists add the following functionality:
74 O(n) removal of any entry in the list.
75 .SS Singly linked tail queues (STAILQ)
76 Singly linked tail queues add the following functionality:
78 Entries can be added at the end of a list.
80 O(n) removal of any entry in the list.
82 They may be concatenated.
86 All list insertions must specify the head of the list.
88 Each head entry requires two pointers rather than one.
90 Singly linked tail queues are ideal for applications with
91 large datasets and few or no removals,
92 or for implementing a FIFO queue.
93 .SS Doubly linked data structures
94 All doubly linked types of data structures (lists and tail queues)
97 Insertion of a new entry before any element in the list.
99 O(1) removal of any entry in the list.
103 Each element requires two pointers rather than one.
104 .SS Doubly linked lists (LIST)
105 Linked lists are the simplest of the doubly linked data structures.
106 They add the following functionality over the above:
108 They may be traversed backwards.
112 To traverse backwards, an entry to begin the traversal and the list in
113 which it is contained must be specified.
114 .SS Doubly linked tail queues (TAILQ)
115 Tail queues add the following functionality:
117 Entries can be added at the end of a list.
119 They may be traversed backwards, from tail to head.
121 They may be concatenated.
125 All list insertions and removals must specify the head of the list.
127 Each head entry requires two pointers rather than one.
128 .SS Doubly linked circular queues (CIRCLEQ)
129 Circular queues add the following functionality over the above:
131 The first and last entries are connected.
135 The termination condition for traversal is more complex.
137 Not in POSIX.1, POSIX.1-2001, or POSIX.1-2008.
140 macros first appeared in 4.4BSD.
142 Some BSDs provide SIMPLEQ instead of STAILQ.
143 They are identical, but for historical reasons
144 they were named differently on different BSDs.
145 STAILQ originated on FreeBSD, and SIMPLEQ originated on NetBSD.
146 For compatibility reasons, some systems provide both sets of macros.
147 Glibc provides both STAILQ and SIMPLEQ,
148 which are identical except for a missing SIMPLEQ equivalent to
149 .BR STAILQ_CONCAT ().