5

I m seeking some equivalent in C of python's set() variable type any ideas? here is the python doc about sets http://docs.python.org/2/library/sets.html

and could you explain/link me a help for this? please

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
Arnaud Aliès
  • 1,079
  • 13
  • 26
  • 2
    Python's `set` is actually a hash table. There's no such thing in standard C, but there are lots of hash table libraries available on the web. – Fred Foo Nov 01 '12 at 14:52
  • I know you explicitly mention C, but if C++ is an option, the [STL](http://en.wikipedia.org/wiki/Standard_Template_Library) might have something for you. – jro Nov 01 '12 at 15:02

2 Answers2

5

No, there isn't. The Python datatype relies on a lot of things regarding Python objects that the more low-level data you typically work with in C simply don't have.

Like being able to compare two "objects" reliably, regardless of their type or internal structure.

The more you know about your data the easier it will be to roll your own, of course.

I would recommend you look at glib's hash tables if you want to use a library.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • To expand on the last point: something like Python's set can be easily implemented with a hash table - a set is simply a hash that maps keys to a dummy value. Before sets were added to Python, it was an idiom to implement a set as a dictionary that maps keys to `None`. – user4815162342 Nov 01 '12 at 15:01
1

Feel free to use my header file for performing all the set operations in C language with ease. Follow the link and please go through the README.md file to get insight about it.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135