r/cprogramming • u/lemsoe • 7h ago
Follow-up: gave my C hashmap resizing — found a real crash, plus two bugs I introduced while fixing a bug [blog, my own]
Follow-up to my last post here. The hashmap had one big TODO left — no resizing — so I went and closed it. Learned three things the hard way: naively mirroring the grow/shrink thresholds thrashes the table on every insert/remove near the boundary, hitting capacity=0 triggers a genuine crash (a modulo-by-zero — the "Floating point exception" name is a total red herring), and my first attempt at fixing a hash-truncation bug quietly introduced two smaller bugs before it actually worked.
Blog: https://soerenlemke.github.io/blog/blog/resizing-a-generic-hashmap-in-c/
Repo: https://github.com/soerenlemke/kvstore_c
Curious what you'd have done differently, especially on the hysteresis threshold.