Data structures in C? [duplicate] - c

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Good STL-like library for C
Are there any open source C libraries with common data structures?
Is there a "standard" library that C programmers use for frequently-used data structures (hash/tree-based sets/maps, heaps, etc.)? Or is there no single, well-known implementation?
(Something kind of like Boost for C++?)

See GLib or APR (Apache Portable Runtime) library, they are the most well-known C libraries for data structures.
http://developer.gnome.org/glib
http://apr.apache.org

Related

Does C have templates? [duplicate]

This question already has answers here:
Is there an equivalent in C for C++ templates?
(7 answers)
Closed 4 years ago.
I've previously worked with C but I'm still a major newby in general.
Currently I'm working on a little project that involves Parallel Computing and for this we are using the language Cilk+.
My objective is to implement a parallel scan pattern using Cilk+ and I've found this reference to the subject, but I don't understand half of the notations on it.
Does C have templates? I thought only C++ had them.
If yes, how do they work? I've found nothing regarding the subject.
If not, then can someone explain me what line 1 and 5 mean?
Thank you in advance!
C does not have templates. C++ does.
Line 1 is using C++ templates.
Line 5 is not standard C or C++. It is part of the Cilk Plus extension.
If this is a new project, you may way to avoid Cilk Plus. It's officially deprecated. Intel is encouraging everyone to switch to OpenMP or TBB instead.

Is Polymorphism possible in C? [duplicate]

This question already has answers here:
How would one write object-oriented code in C? [closed]
(32 answers)
Closed 8 years ago.
Can I include or declare a function inside a structure? I am trying to achieve polymorphism in C. If defining a function isn't the correct way to do it, what other methods can I use?
Polymorphism as a feature of object-oriented languages is not available in C. Neither are encapsulation and inheritance - the language does not have the corresponding features.
This does not mean, however, that it is impossible to model the corresponding behavior with the regular features of C: it is possible to build a library that lets you produce behavior that looks like polymorphism, for example, by using arrays of function pointers.

R*-Tree C Implementation? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
C++ R - tree implementation wanted
I've been hunting just about all evening...
Anyone know of a R*-Tree implementation that builds on a modern C compiler?
Thanks,
Chenz
SQLite's R* Tree might interest you. It is under public domain or such free license and builds with gcc.

Object Oriented pattern in C? [duplicate]

This question already has answers here:
How would one write object-oriented code in C? [closed]
(32 answers)
Closed 1 year ago.
Possible Duplicate:
Can you write object oriented code in C?
I am writing a large application in C and have heard that prior to the advent of C++ programmers used to implement the "Object Oriented" pattern in C. My question is what is the usual form this pattern takes? and how would I go about implementing such an OOP pattern in a modern C application?
Here are a few helpful links to guides on Object Oriented C:
Object Oriented Programming with C - A very thorough treatment of the subject.
Phil's guide to object-oriented C - This is a rather simplistic approach to the subject, imo.
GObject Reference Manual - GObject is used heavily throughout Gnome and GTK+ applications (mostly on Linux) and therefore provides a thorough example of Object Oriented C in the real world.
Where a C++ object has methods, object-style 'C' takes a struct full of function pointers. The functions corresponding to a member function have an explicit data argument that takes the place of the implied 'this' pointer.
Subclasses use function-pointer structs of the same type, with different function pointers to indicate overridded methods.
I used to simply adopt naming conventions for a structure and associated "methods".
Each method would begin with e.g. CANDIDATE_ for a candidate object, and be associated with a typedef CANDIDATE { ... }, and be in a file Candidate.c
An additional link from someone who wrote several OO frameworks for C.

Container Class / Library for C [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
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:
Client code should be able to create containers for multiple different data types without modifying the library.
The interface for creating and using the containers should be intuitive.
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.
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.
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.
How about ccl? This is a container library which has been (unsuccessfully) proposed for C standard. Maybe it's best fit for you. You can see https://code.google.com/p/ccl/ https://github.com/jacob-navia/ccl.
Enjoy it.
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).
#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.
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)
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

Resources