3 ms·
String Matching Based on Compile Time Perfect Hashing in Zig
- sytelus 8y agoThis is very cool. So could this finally make efficient switch() statements with string keys a reality?
- xxs 8y agojava switch/case impl. is hash based but it includes equals as well. Perfect hashing might work for short string but overall it won't be a major improvement to contents check (one deference)
- rurban 8y agoNice and fast trick to find perfect hashes, but for more strings there should be a fallback to the traditional methods: gperf (finding unique bytes) and an indirect table lookup for hit and miss with offset
- jononor 8y agoVery interesting. I've been thinking about writing a JSON parser for microcontrollers that would work something like this. Typically in these cases one only needs to support objects with a fixed set of keys, so such an approach could take less progmem (no storing of string literals).