▲ | jlokier 4 days ago | |||||||
If you can search (and do other operations) on a linked list, and the lists are long enough to matter, you can trivially speed it up to a fixed-size hash table with hardly any code changes. This:
becomes:
This:
becomes:
etc.A simple hash(), not high quality but good enough for non-adversarial inputs, can be a one-liner. A good dictionary does more than this of course, especially dynamic sizing, but this simple change can radically speed up simple linked list code when the lists are long, you don't have a hash table implemention you can use, and you want to keep the code change very small. The same principle can be used with other things than lists too. | ||||||||
▲ | bluGill 4 days ago | parent [-] | |||||||
Those would be useful optimizations once the simplest thing works. However the goal here is 500 lines- not fast, correct, maintainable code. If I was to write this for real world use I wouldn't start with C in the first place. | ||||||||
|