Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a simple C library for a set of integer sets?

Tags:

c

integer

set

I've got to modify a C program and I need to include a set of unsigned integer sets. That is, I have millions of sets of integers (each of these integer sets contains between 3 and 100 integers), and I need to store these in some structure, lets call it the directory, that can in logarithmic time tell me whether a given integer set already exists in the directory. The only operations that need to be defined on the directory is lookup and insert.

This would be easy in languages with built-in support for useful data structures, but I'm a foreigner to C and looking around on Google did (surprisingly) not answer my question satisfactorily. This project looks about right:

http://uthash.sourceforge.net/

but I would need to come up with my own hash key generator.

This is a standard, simple problem, so I hope there is a standard and simple solution.

like image 821
conradlee Avatar asked Mar 23 '10 13:03

conradlee


1 Answers

It depends on what you are going to do with the data. But maybe tsearch does already what you want. You could also build a sorted array for each set and look up the values with bsearch, although the performance may suffer during the insertion.

EDIT: If you are looking for an (external) library, you'll find a comparision of some C and C++ hash table implementation here. The author of the article has written a generic header implementation called khash. So you're compiled binary don't have any additional dependencies.

like image 105
quinmars Avatar answered Oct 02 '22 20:10

quinmars