CDS — Intrusive C Data Structures
Seven single-header libraries providing high-performance, intrusive
data structures for C17: singly and doubly linked lists, an
open-addressing hash table, an AVL tree, a Patricia trie, a pairing
heap, and a union-find forest.
Intrusive means link pointers live inside your own structs — no hidden
allocations, no wrapper nodes. A single object can belong to a hash
table and a sorted tree simultaneously, just by embedding two link
fields. Removing an object from all its containers is a single free.
Each header is self-contained: drop it into your project and include it.
A two-macro idiom (X_LINK in your struct, X_DEFINE once in your code)
generates a complete, type-safe API under a prefix of your choosing.
All generated functions are static inline; there is nothing to compile
or link.
Every algorithm is iterative — no recursion anywhere — making the
library safe for interrupt handlers, OS kernels, and embedded systems
with limited stack depth.
Highlights:
- Single/Double/XOR linked lists
- Hash table — Robin Hood hashing with backward-shift deletion; no
tombstones; O(1) amortised insert, find, and remove
- AVL tree — O(log n) insert, remove, and five boundary queries
(find_ge, find_gt, ...); six iterator-seek variants for range scans;
O(n) bulk load; doubles as a min/max priority queue
- Patricia trie — O(k) operations on arbitrary byte-string keys; prefix
queries and prefix iteration built in
- Pairing heap — O(1) insert and meld; ideal for Dijkstra, Prim, and
event schedulers
- Union-find — path compression + union by rank; O(alpha(n)) per
operation
- Thing_list
Includes demo programs, benchmark suites, man pages, and a full
reference manual.