Metriche repository
- Star
- (133.883 star)
- Metriche merge PR
- (Nessuna PR mergiata in 30 g)
Descrizione
Currently we implement switch statements with binary search. This works well for values that fit into a register, but for strings it might be better to compute a hash function.
Some thoughts:
-
Even in the simple case of using a full hash function, exactly two passes over the switched value is probably better than O(log N) possible passes over it.
-
Since we have the expected keys statically, we can use a simple, cheap universal hash (e.g., FNV? djb2?) and keep trying different seeds until we get one without any collisions.
-
Instead of hashing all of the input bytes, we can hash just enough of them to avoid collisions.
-
We can try using a minimal (or near minimal) perfect hash to emit a jump table instead of binary search. (This might even be useful for sparse integer values too.)
If someone can help figure out code that can take a []string and figures out an appropriate and cheap hash function to use, I can help wire it into swt.go.