I'm looking for a C library with common reusable data structures like linked lists, hash tables etc. Something like the source distributed with Mastering Algorithms with C (Paperback) by Kyle Loudon.
- 
                    Other sites are better suited to these kinds of questions https://www.slant.co/improve/topics/19233 – ideasman42 Aug 03 '19 at 03:09
 
8 Answers
BSD queue.h has:
- SLIST = singly linked list
 - LIST = doubly linked list
 - SIMPLEQ = singly linked queue
 - TAILQ = doubly linked queue
 
BSD tree.h has:
- RB - red-black tree
 - SPLAY - splay tree
 
See the queue(3) and tree(3) man pages for details. I really like them because they are pure C macros without dependencies (not even libc). Plus with the BSD license you don't have to worry about any company restrictions w/ GPL.
- 25,870
 - 6
 - 90
 - 122
 
- 1,836
 - 10
 - 7
 
Gnome provides an excellent library for this, called Glib, with many useful data structures and other utilities as well.
- 48,117
 - 14
 - 92
 - 101
 
- 39,840
 - 10
 - 78
 - 97
 
gnulib, the gnu portability library.
It's distributed as source code. This list is from its module list, which includes a TON of other things. One interesting one is "c-stack: Stack overflow handling, causing program exit."
- list
 - array-list
 - carray-list
 - linked-list
 - avltree-list
 - rbtree-list
 - linkedhash-list
 - avltreehash-list
 - rbtreehash-list
 - sublist ( Sequential list data type backed by another list. )
 - oset (Abstract ordered set.)
 - array-oset
 - avltree-oset
 - rbtree-oset
 
- 9,643
 - 9
 - 35
 - 39
 
- 
                    1Keep in mind that this option is GPL-licensed, and therefore can only be used legally in GPL-licensed software. – Noah Andrews Jul 09 '19 at 20:09
 
SGLIB is an excellent generic data-structures library. The library currently provides generic implementations for: 
sorting arrays 
linked lists 
sorted linked lists 
double linked lists 
red-black trees 
hashed containers 
It's very fast, faster than glib. It's inspired by the Standard Template Library. Download Here
Another solution is Attractive Chaos software. 
C macro library: 
kbtree.h: efficient B-tree library in C.
khash.h: fast and light-weighted hash table library in C.
kvec.h: simple vector container in C.
Sglib and Attractive Chaos software are C macros library. Using void* to implement generic containers in C may be inefficient. C macros mimics C++ template and are as efficient as C++ template
- 9,005
 - 2
 - 31
 - 44
 
- 1,893
 - 2
 - 13
 - 9
 
- 
                    
 - 
                    The "download" link for the SGLIB project is broken. Seems like going defunct... :/ – luis.espinal Oct 21 '10 at 04:24
 - 
                    @luis.espinal It can still be downloaded from http://freecode.com/projects/sglib – Rob Mar 16 '12 at 16:29
 - 
                    1
 - 
                    klib has some activity, but i cant find any other hashtable fast as this, someone has some other option? https://github.com/attractivechaos/klib/commits/master – Ciro Spaciari Jan 01 '22 at 16:58
 
- 
                    This points to a page saying that the library has moved off to http://code.google.com/p/clibutils/. – stakx - no longer contributing Aug 13 '12 at 18:35
 - 
                    1And now it appears to be: https://github.com/davinash/cstl It hasn't been updated since 2012 though. – domen Jul 24 '17 at 09:24