Hacker News new | past | comments | ask | show | jobs | submit login

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.



there 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...


Interesting that the manpage claims it conforms to POSIX.1-2001.

https://linux.die.net/man/3/hcreate


POSIX is the standard for Unix, not for C.


I 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.


Come 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.


You can add with hsearch; set ACTION=ENTER

Also you could 'delete' with item.data set to some sentinel.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: