Hey everyone! I've recently started diving into C programming, mainly because I want my projects to be low-maintenance and last a long time. In other languages, I've found Hashmaps to be super handy for efficient access to elements and for using 'contains' methods. If you have experience with C, how do you go about achieving this? Do you use a specific C implementation, or maybe you have some tips or tricks?
5 Answers
For something quick and easy, I really like the Convenient Containers library. It covers a lot of data structure needs. If you prefer something smaller, check out the stb collection of single-header libraries, especially the stb_ds for data structures.
If you're looking for long-term stability, are you sure C is the way to go? It might not be the best choice if you want zero maintenance for years. Just saying!
C is solid for this purpose! It rarely changes, and most old code still compiles. Sure, libraries might evolve, but your own implemented hashmap will last for years.
Writing your own Hashmap can be a fun challenge! It's usually about 50 lines of C for a basic open-addressed version. I suggest using the FNV-1 hash function for efficiency. You might also want to consider using a bloom filter to check for existence without having to search through everything, which can slow things down.
I remember when I had to implement these before the internet was a wealth of information. Sometimes, it's just simpler to code it yourself instead of scouring libraries! It saves time in the long run.
True, but implementing a correct and efficient hashmap in C can get tricky! It's a tough task.
Do you really need a Hashmap? If it’s essential, you might want to consider C++. It's quite stable as well!
Exactly! Plus, C++ gives you so many options for data structures and it can as well handle those needs.
Right? Stability is key!
You might want to try using Glib's hashtable. Just keep in mind that you’ll need to implement your own 'contains' method using the HashTableIter, along with `g_hash_table_find`. It's a little extra work, but it gets the job done!

What would you suggest instead? Java and Python seem to give me headaches with version changes. It's a hassle managing multiple versions.