queue(7)

โœจ queue(7) โ€” the manual page, but make it a group chat โœจ

okay bestie, so this is queue(7) from the Miscellaneous Information Manual, and it's literally the glow-up guide for <sys/queue.h> ๐Ÿ’– Like, this is the header that hands you a whole wardrobe of macros for building and living in linked lists and queues. No cap, it's giving foundational. Let's get into it. ๐Ÿฆ‹


๐ŸŒธ NAME ๐ŸŒธ

queue โ€” implementations of linked lists and queues


๐Ÿ’… DESCRIPTION ๐Ÿ’…

The <sys/queue.h> header file provides a set of macros that define and operate on the following data structures:

  • SLIST โ€” singly linked lists ๐Ÿ“
  • LIST โ€” doubly linked lists
  • STAILQ โ€” singly linked tail queues
  • TAILQ โ€” doubly linked tail queues
  • CIRCLEQ โ€” doubly linked circular queues ๐Ÿ‘‘

All structures support the following functionality:

  • Insertion of a new entry at the head of the list.
  • Insertion of a new entry after any element in the list.
  • O(1) removal of an entry from the head of the list.
  • Forward traversal through the list.
lowkey important: code size and execution time depend on the complexity of the data structure being used, so programmers should take care to choose the appropriate one. Like, pick your fighter intentionally, don't just grab the first one. ๐Ÿ™ˆ

๐ŸŽ€ Singly linked lists (SLIST) ๐ŸŽ€

SLIST is the simplest of the bunch โ€” the baby of the family, the no-frills icon. It supports only the functionality listed above (head insertion, insert after any element, O(1) removal from the head, forward traversal) and nothing else.

Where it eats: SLIST is ideal for applications with large datasets and few or no removals, or for implementing a LIFO queue. โœจ

SLIST adds the following functionality:

  • O(n) removal of any entry in the list.

๐Ÿงš Singly linked tail queues (STAILQ) ๐Ÿงš

STAILQ adds the following functionality:

  • Entries can be added at the end of a list.
  • O(n) removal of any entry in the list.
  • They may be concatenated.

However:

  • All list insertions must specify the head of the list.
  • Each head entry requires two pointers rather than one.

STAILQ is ideal for applications with large datasets and few or no removals, or for implementing a FIFO queue. periodt. ๐Ÿ’œ


๐Ÿ‘‘ Doubly linked data structures ๐Ÿ‘‘

All doubly linked types of data structures (lists and tail queues) additionally allow:

  • Insertion of a new entry before any element in the list.
  • O(1) removal of any entry in the list.

However:

  • Each element requires two pointers rather than one.

like yeah, extra pointers, extra power. main character tax. ๐Ÿ’…


๐ŸŒˆ Doubly linked lists (LIST) ๐ŸŒˆ

LIST is the simplest of the doubly linked data structures. Over everything above, they add the following functionality:

  • They may be traversed backwards.

However:

  • To traverse backwards, an entry to begin the traversal and the list in which it is contained must be specified.

so like, backwards vibes require receipts. both of them. ๐Ÿ˜ญ


โญ Doubly linked tail queues (TAILQ) โญ

TAILQ adds the following functionality:

  • Entries can be added at the end of a list.
  • They may be traversed backwards, from tail to head.
  • They may be concatenated.

However:

  • All list insertions and removals must specify the head of the list.
  • Each head entry requires two pointers rather than one.

๐Ÿฆ‹ Doubly linked circular queues (CIRCLEQ) ๐Ÿฆ‹

CIRCLEQ adds the following functionality over the above:

  • The first and last entries are connected.

However:

  • The termination condition for traversal is more complex.
fr fr, watch that termination condition. it's the plot twist of this whole data structure. ๐Ÿ™ˆ

๐Ÿ“œ STANDARDS ๐Ÿ“œ

BSD.


๐Ÿ•ฐ๏ธ HISTORY ๐Ÿ•ฐ๏ธ

<sys/queue.h> macros first appeared in 4.4BSD.


๐Ÿซถ NOTES ๐Ÿซถ

Some BSDs provide SIMPLEQ instead of STAILQ. They are identical, but for historical reasons they were named differently on different BSDs. STAILQ originated on FreeBSD, and SIMPLEQ originated on NetBSD. For compatibility reasons, some systems provide both sets of macros. glibc provides both STAILQ and SIMPLEQ, which are identical except for a missing SIMPLEQ equivalent to STAILQ_CONCAT().


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

circleq(3), insque(3), list(3), slist(3), stailq(3), tailq(3)


and that's the whole page bestie, no skips, no crumbs left ๐Ÿ’– this one shipped as Linux man-pages 6.20, dated 2025-05-17 โ€” go forth and pick the right container, slay, and remember: choose your data structure like you choose your playlist. deliberately. ๐ŸŽ€๐Ÿซถโœจ

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: BSD-3-Clause
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms