tags:

views:

193

answers:

3

Is there a C library version of the C++ std::map in a standard library?

+1  A: 

There is nothing built into the standard library, but uthash may meet your needs.

Brian R. Bondy
+3  A: 

The C standard library does not support such an equivalent. However, a commonly used C library is GLib from the GNOME project. In particular, the GLib Hash Tables may be what you're looking for.

Greg Hewgill
Did the question change, or did you just roll to disbelieve that anyone would actually want a tree rather than a hash? ;-) The GLib tree is here: http://library.gnome.org/devel/glib/stable/glib-Balanced-Binary-Trees.html
Steve Jessop
+3  A: 

std::map is not a hash table. Therefore, my suggestion: Red-Black Tree C Code

The following C files implement balanced binary trees using the red-black paradigm. I have written these functions in a very general manner so that the key can be anything at all. Each node of the balanced binary tree must contain a key and a pointer to info. The user defines what data-type the key is and provides a comparison function for the keys. The info can also be any kind of data type.

(Disclaimer: haven't tried it myself.)

Pukku