5 ms·
Yeah... it’s easy to write small code that doesn’t work.
by valleyer 12y ago
Yeah... it’s easy to write small code that doesn’t work.
- userbinator 12y agoIt's not hard to fix, however - one extra modulus, as far as I can see.
- valleyer 12y agoAnd an extra local variable. Which might take up a line of source code!
- ExpiredLink 12y agoWith two additional casts you can make it compile[1] as C++ - without the incredibly wasteful extra local variable. [1] http://codepad.org/ http://codepad.org/
- vog 12y agoYour link to "http://codepad.org/" http://codepad.org/" doesn't show any code. Did you forget some arguments in the URL?
- ExpiredLink 12y agohttp://codepad.org/LuQpUhmj http://codepad.org/LuQpUhmj
- pwr22 12y agoTechnically 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 https://gist.github.com/pwr22/a08597e475d1aa44cd96 It will still fail looking up a non-existent key, which I don't understand
- hawski 12y ago>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.
- pwr22 12y agoSorry, non-existent keys return a slot but since it isn't allocated it blew up when I was trying to print out its values :(