23 ms·
I was surprised recently when looking at different hash tables that have been implemented in C to discover that the standard library includes its own hash table
by jandrese 3y ago
I was surprised recently when looking at different hash tables that have been implemented in C to discover that the standard library includes its own hash table. They are even part of POSIX. There is a reason you have never heard of it, or if you have you have never used it. In true POSIX fashion they are close to useless. The implementation doesn't allow you to modify the table after it has been created, you have to pass in all the data when you create the table. There is no add or delete and you can't change any value you pull from the table. It also stores the data in a static area local to the function so you can only use a single table in a program at a time. It doggedly commits every C stdlib sin possible.
- zabzonk 3y agothere are no hash tables in the Standard C Library - POSIX does not define Standard C. more info: https://stackoverflow.com/questions/6118539/why-are-there-no-hashtables-in-the-c-standard-library https://stackoverflow.com/questions/6118539/why-are-there-no...
- jandrese 3y agoInteresting that the manpage claims it conforms to POSIX.1-2001. https://linux.die.net/man/3/hcreate https://linux.die.net/man/3/hcreate
- jlarocco 3y agoPOSIX is the standard for Unix, not for C.
- loeg 3y agoI think GP is talking about, e.g., glibc, or any libc you might find on a POSIX system, rather than the abstract C standard library. I agree that as a point of clarity, POSIX isn't standard C and the crappy hashtable described is in POSIX, not standard C.
- emmelaich 3y agoYou can add with hsearch; set ACTION=ENTER Also you could 'delete' with item.data set to some sentinel.
- boffinAudio 3y agoCome on, this is a straw man argument. That function was built for a specific purpose, and the fact you had to hunt for it means its not meant for general purpose use. Besides which, this statement is just inflammatory: "In true POSIX fashion they are close to useless." The straw man does not support the conclusion .. POSIX is full of utility.