3 ms·
> except for sparse case values Even for sparse case values the compiler will emit a binary search once the list of labels is long enough.
by brandmeyer 8y ago
> except for sparse case values
Even for sparse case values the compiler will emit a binary search once the list of labels is long enough.
- convolvatron 8y agoi’m pretty sure i’ve heard of compilers generating a perfect hash (since the key space is known) also
- vardump 8y agoThis has been my expectation as well, but haven't seen this in real life. I guess the main issue is that the compiler will need to also ensure no value outside the expected set can match a case statement either (no match and default cases), which kinda negates the benefit. Maybe there are cases this is generated, anyone seen compiler generating those? I wonder whether it is possible to generate reversible (almost) perfect "hashes"? I mean a hash where every unique input value is guaranteed to map to a unique output value. Because this kind of hash could be used to handle no-match/default case safely.