Are there any open source C libraries with common data structures?

CData Structures

C Problem Overview


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.

C Solutions


Solution 1 - C

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.

Solution 2 - C

Gnome provides an excellent library for this, called Glib, with many useful data structures and other utilities as well.

Solution 3 - C

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

Solution 4 - C

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

Solution 5 - C

The GDSL Library might be a good thing to consider:

http://home.gna.org/gdsl/

Solution 6 - C

The Apache Portable Runtime.

Solution 7 - C

Solution 8 - C

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVasilView Question on Stackoverflow
Solution 1 - CHUAGHAGUAHView Answer on Stackoverflow
Solution 2 - CEmil HView Answer on Stackoverflow
Solution 3 - CIan KellingView Answer on Stackoverflow
Solution 4 - CLearView Answer on Stackoverflow
Solution 5 - Cluis.espinalView Answer on Stackoverflow
Solution 6 - CJaapView Answer on Stackoverflow
Solution 7 - CAvinashView Answer on Stackoverflow
Solution 8 - CzvrbaView Answer on Stackoverflow