Had an interesting conversation with a buddy last night. It started out as a shift-reduce problem with Bison and ended up a ping-pong of useful UNIX API:s. We concluded that despite having worked professionally with UNIX for over a decade, it is still very satisfying finding gems like these.
Most people are unaware they existing and therefore often end up rolling their own (buggy) implementations.
Mangage a simple queue:
Manage hash search table:
Manage a binary search tree:
Linear search and update:
This header has lots of macros for handling various forms of
linked lists. The version in GLIBC is a bit behind the BSD’s, because
the latter also have
_safe() versions of some macros to aid the user
in some tricky cases, e.g. when removing entries while iterating.
Several types of lists are supported:
- LIST: Doubly linked list
- SLIST: Single linked list
- STAILQ: Single linked tail queue
- SIMPLEQ: Simple queue
- TAILQ: Tail queue
- CIRCLEQ: Circular queue
Here’s a few of them:
I wrote a demo of the TAILQ API a couple of years ago.
Other Noteworthy API’s
Other functions worthy of mentioning here are: