Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Container Class / Library for C [closed]

Tags:

c

containers

Does anyone know of any C container libraries? I am looking for something which gives standard implementations of linked lists, arrays, hash tables etc, much in the same way as the C++ STL does. Key concerns are:

  1. Client code should be able to create containers for multiple different data types without modifying the library.
  2. The interface for creating and using the containers should be intuitive.
like image 407
Howard May Avatar asked Nov 20 '08 15:11

Howard May


People also ask

What are the containers in C?

In C++, there are generally 3 kinds of STL containers: Sequential Containers. Associative Containers. Unordered Associative Containers.

What is a container in C #?

A container is a holder object that stores a collection of other objects (its elements). They are implemented as class templates, which allows great flexibility in the types supported as elements.

What is container library?

The Containers library is a generic collection of class templates and algorithms that allow programmers to easily implement common data structures like queues, lists and stacks.

What are container classes in C++?

Containership in C++ And the class which contains the object and members of another class in this kind of relationship is called a container class. The object that is part of another object is called contained object, whereas object that contains another object as its part or attribute is called container object.


8 Answers

I just came across SGLIB while looking for a C implementation of a map/dictionary container. Unfortunately, no map but it seems to include the containers you asked about. I have no idea how good it is.

http://sglib.sourceforge.net.

like image 158
Nick Van Brunt Avatar answered Oct 06 '22 01:10

Nick Van Brunt


Sglib is an excellent generic data structures library. The library currently provides generic implementation for:

  • sorting arrays
  • linked lists
  • sorted linked lists
  • double linked lists
  • red-black trees
  • hashed containers

It's very fast. Faster that glib. It's inspired by the Standard Template Library. Download here

Another solution is Attractive Chaos sotware. 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.

Kulesh Shanmugasundaram presents the generic Linux Kernel Linked List and a generic hash table based in the Linux Kernel Linked List.

Sglib and Attractive Chaos sotware and Linux Kernel Linked List are C macro libraries. Using void* to implement generic containers in C may be inefficient. C macros mimic C++ templates and are as efficient as a C++ template.

like image 41
Lear Avatar answered Oct 05 '22 23:10

Lear


Chuck Falconer has a decent hash library written in C that includes a C++ interface, click on hashlib.zip on the webpage to download.

Ben Pfaff has very nice and extremely well-documented binary and balanced tree library, GNU libavl, that implements most major tree structures including binary search trees, AVL trees, red-black trees and threaded versions of each.

libavl is licensed under the LGPL (as of version 2.0.3), hashlib is GPL.

I'm not sure what you are looking for as far as arrays and linked lists go as the former is supported directly by the language and the latter is generally trivial enough to implement without warranting a library.

like image 29
Robert Gamble Avatar answered Oct 06 '22 00:10

Robert Gamble


How about ccl? This is a container library for C. Maybe it's best fit for you. You can see https://code.google.com/p/ccl/. Enjoy it.

like image 44
pwrlove Avatar answered Oct 06 '22 01:10

pwrlove


I've been using a library I've been growing from Hanson's "C Interface and Implementations" book. His source is downloadable at

cii book website

Everything is an Abstract Data Type. There is List, Set, Table (map).

like image 25
navicore Avatar answered Oct 06 '22 00:10

navicore


#include "queue.h" to get access to the implementations of singly-linked lists, singly-linked tail queues, lists and tail queues.

I found a generic cache for storing arbitrary objects in memory by D. J. Bernstein (http://cr.yp.to/djbdns.html) to be both clean, simple and super fast. Look up cache.h and cache.c in djdns tarball.

like image 20
user105991 Avatar answered Oct 06 '22 01:10

user105991


Some of the ones that I have heard of (but never used) are

  • Glib
  • iMatix Standard Function Library
  • disparate elements from the Linux kernel headers (e.g. list)
like image 22
Sandeep Avatar answered Oct 06 '22 01:10

Sandeep


This seems to cover most of the containers and some algorithms. There is also no licensing, all the headers contain - 'code may be used without restriction.' http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=13867&lngWId=3

like image 44
MockM4XMacro Avatar answered Oct 06 '22 01:10

MockM4XMacro