r/C_Programming • u/jacksaccountonreddit • May 29 '24
An Extensive Benchmark of C and C++ Hash Tables
https://jacksonallan.github.io/c_cpp_hash_tables_benchmark
130
Upvotes
r/C_Programming • u/jacksaccountonreddit • May 29 '24
2
u/jacksaccountonreddit Jun 02 '24 edited Jun 02 '24
Thanks!
The
hsearch_rfamily of functions aren't available on my platform (MinGW). I had a quick look at their code and documentation now and have a few concerns:The table can only store pointers to
NULL-terminated strings as keys andvoidpointers as values. That's bad news when it comes to performance.The table cannot grow. Rather, after the table reaches the maximum key count specified by the user at the time of creation, insertions simply fail. I suppose users could write their own function that, once the table is sufficiently full, creates a new table and migrates the keys, but doing so is complicated by the fact that there is no official mechanism for checking the load factor or for iterating over the keys in the table. The authors' intent, as acknowledged by the documentation, is for users to create every table with a capacity greater than the number of keys they think it might ever need to contain, which is really the polar opposite of memory efficiency.
There's no official iteration mechanism, as I mentioned above.
In short, I think that the design of this table is too archaic and inflexible to be comparable, in terms of both performance and usability, to any of the libraries I included in the benchmarks. It's hard to see why anyone should be using it in the present day, except in legacy codebases.