Is learning how to create a hash table necessary for a software engineer?
15-line hash table in C
41–50 of 104 posts
Re: 15-line hash table in C
#42Re: 15-line hash table in C
#43Is learning how to create a hash table necessary for a software engineer?
Mainly because they are simple, and lot of problems are solvable by using them without resorting to Someone Elses Gigantic Platform Framework.
Re: 15-line hash table in C
#44Earlier quoted context omitted.
Yeah... it’s easy to write small code that doesn’t work.
It's not hard to fix, however - one extra modulus, as far as I can see.
... & (SIZE - 1)
but it looks broken because t does the C-ish mutating accumulator thing rather than acting as a base and using h as an offsetYou need a temporary variable of
int (**)[2]
to avoid doing two additions per iter, though maybe the compiler can pick that up and do it for you. Anyway, this no longer crashes but it now runs forever if the hash fillshttps://gist.github.com/pwr22/a08597e475d1aa44cd96
It will still fail looking up a non-existent key, which I don't understand
Re: 15-line hash table in C
#45Is learning how to create a hash table necessary for a software engineer?
So, no... and yes. You can call yourself a software engineer without knowing any of this stuff, but you will be a better one if you do.
Re: 15-line hash table in C
#46[1]: http://attractivechaos.github.io/klib/#Khash%3A%20generic%20...
Re: 15-line hash table in C
#47I will not understand how and why people's egos get threatened by things like this.
Re: 15-line hash table in C
#48For those of us who actually ship code, I'd like to suggest khash[1], which is a pretty nice implementation of a hash table in C. It uses lot's of macros, so if you're looking for a brain teaser you will be satisfied as well :) [1]: http://attractivechaos.github.io/klib/#Khash%3A%20generic%20...
Re: 15-line hash table in C
#49I love how a comment thread about a fun little program turned into HN showing off their wisdom in software engineering coupled with occasional boasting about tight code reviews. I will not understand how and why people's egos get threatened by things like this.
Re: 15-line hash table in C
#50Earlier quoted context omitted.
It's not hard to fix, however - one extra modulus, as far as I can see.
Technically there is bounds checking ... & (SIZE - 1) but it looks broken because t does the C-ish mutating accumulator thing rather than acting as a base and using h as an offset You need a temporary variable of int (**)[2] to avoid doing two additions per iter, though maybe the compiler can pick that up and do it for you. Anyway, this no longer crashes but it now runs forever if the hash fills https://gist.github.c…
In C99 it's allowed to declare in the loop preamble. True for ANSI-C.