News for hackers. Stuff that matters.
Re:15-line hash table in C by pwr22 on Friday December 12, 2014 @02:27AM (#8738927)
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.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 by hawski on Friday December 12, 2014 @04:01AM (#8739136)
>Due to C there is no way to declare both an int and that in the loop preamble so you'd need at least one more line

In C99 it's allowed to declare in the loop preamble. True for ANSI-C.

Re:15-line hash table in C by pwr22 on Friday December 12, 2014 @04:25AM (#8739203)
Not differing types
Re:15-line hash table in C by camgunz on Friday December 12, 2014 @01:27PM (#8741818)
If you really want to, I think you might be able to declare a struct in there. A curse on your house though....
Re:15-line hash table in C by pwr22 on Friday December 12, 2014 @05:36PM (#8743135)
In the end I wanted the variable to persist beyond the end of the loop anyway
Re:15-line hash table in C by pwr22 on Friday December 12, 2014 @04:38AM (#8739244)
Sorry, non-existent keys return a slot but since it isn't allocated it blew up when I was trying to print out its values :(