strlen.3, wcslen.3: Recommend alternatives where input buffer might not be null-termi...
[man-pages.git] / man7 / queue.7
blob3973e8211e8b17107ae5e39086de17806edccfc1
1 .\" Copyright (c) 1993
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>
4 .\"
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
8 .\" are met:
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.
17 .\"
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
28 .\" SUCH DAMAGE.
29 .\" %%%LICENSE_END
30 .\"
31 .\"
32 .TH QUEUE 7 2021-03-22 "GNU" "Linux Programmer's Manual"
33 .SH NAME
34 queue \- implementations of linked lists and queues
35 .SH DESCRIPTION
36 The
37 .I <sys/queue.h>
38 header file provides a set of macros that
39 define and operate on the following data structures:
40 .IP * 3
41 singly linked lists (SLIST)
42 .IP *
43 doubly linked lists (LIST)
44 .IP *
45 singly linked tail queues (STAILQ)
46 .IP *
47 doubly linked tail queues (TAILQ)
48 .IP *
49 doubly linked circular queues (CIRCLEQ)
50 .PP
51 All structures support the following functionality:
52 .IP * 3
53 Insertion of a new entry at the head of the list.
54 .IP *
55 Insertion of a new entry after any element in the list.
56 .IP *
57 O(1) removal of an entry from the head of the list.
58 .IP *
59 Forward traversal through the list.
60 .\".IP *
61 .\" Swapping the contents of two lists.
62 .PP
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:
73 .IP * 3
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:
77 .IP * 3
78 Entries can be added at the end of a list.
79 .IP *
80 O(n) removal of any entry in the list.
81 .IP *
82 They may be concatenated.
83 .PP
84 However:
85 .IP * 3
86 All list insertions must specify the head of the list.
87 .IP *
88 Each head entry requires two pointers rather than one.
89 .PP
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)
95 additionally allow:
96 .IP * 3
97 Insertion of a new entry before any element in the list.
98 .IP *
99 O(1) removal of any entry in the list.
101 However:
102 .IP * 3
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:
107 .IP * 3
108 They may be traversed backwards.
110 However:
111 .IP * 3
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:
116 .IP * 3
117 Entries can be added at the end of a list.
118 .IP *
119 They may be traversed backwards, from tail to head.
120 .IP *
121 They may be concatenated.
123 However:
124 .IP * 3
125 All list insertions and removals must specify the head of the list.
126 .IP *
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:
130 .IP * 3
131 The first and last entries are connected.
133 However:
134 .IP * 3
135 The termination condition for traversal is more complex.
136 .SH CONFORMING TO
137 Not in POSIX.1, POSIX.1-2001, or POSIX.1-2008.
138 Present on the BSDs.
139 .I <sys/queue.h>
140 macros first appeared in 4.4BSD.
141 .SH NOTES
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 ().
150 .SH SEE ALSO
151 .BR circleq (3),
152 .BR insque (3),
153 .BR list (3),
154 .BR slist (3),
155 .BR stailq (3),
156 .BR tailq (3)
157 .\" .BR tree (3)