3 ms·
Another option would be using https://www.gnu.org/software/gperf/ https://www.gnu.org/software/gperf/
by jbn 8y ago
Another option would be using https://www.gnu.org/software/gperf/ https://www.gnu.org/software/gperf/
- anarazel 8y agoWe looked at that, and the generated code/hash unfortunately isn't that good.
- souprock 8y agoIt can be made good. I used it for parsing /proc/PID/status keywords at a very high rate to support "top" and "ps". You'll have to change the generated code, which likely means that you use gperf during development instead of running it during every build. The first step was to put only the needed keywords in a file, without the colons. I ran gperf with options to choose 3 specific character offsets and to use the length in the calculation; this was best after I tried a few choices. I then cleaned up the code and optimized it. I rounded the table size up to a power of 2, padding it correctly, and changed the length check to a mask. I switched the code over to using gcc's computed goto extension. I provided the keyword lengths, letting me use memcmp instead of strcmp. I inlined everything.
- rurban 8y agoI evaluated most of the available perfect hash generators a while ago, and gperf is not often the best. I've created much better ones. But I haven't added this NetBSD code yet and also not yet the new perl5 mph code, will do soon. https://github.com/rurban/Perfect-Hash https://github.com/rurban/Perfect-Hash