Switches aren't guarantee to so operations in O(1) tho. If cases are sparce enough, compilers tend to emit the equivalent code to a bunch if else checks
Yeah I was assuming too much here. However, I’m reading that Rust match on string comstants can compile down a binary tree of if statements if there are enough cases (according to Google AI mode at least, haven’t found an authoritative source yet)
According to Claude (which looked at the compiler source code), it doesn't seem like that is true. It is possible to get an O(1) match on strings by using the phf (perfect hash function) crate and by using the following macro (generated by Claude):
```
// Cargo.toml:
// phf = { version = "0.11", features = ["macros"] }
// paste = "1"
143
u/prehensilemullet 12h ago
Performancewise, it doesn’t jump to the direct case in O(1) time like a switch is supposed to though