Ilan Schnells AOT generator for perfect hash functions[0] has served me well. It takes a code template so you can generate code for any language. It also uses the much more elegant CHM algorithm[1] (Which is also implemented by the venerable CMPH library[2] if you want to compute these things dynamically.)<p>If I was doing dynamically in C++, like the author of this post, and didn&#x27;t want to add a runtime dependency, I might be tempted to implement CHM using Boost Graph.<p>[0] <a href="http:&#x2F;&#x2F;ilan.schnell-web.net&#x2F;prog&#x2F;perfect-hash&#x2F;" rel="nofollow">http:&#x2F;&#x2F;ilan.schnell-web.net&#x2F;prog&#x2F;perfect-hash&#x2F;</a><p>[1] <a href="http:&#x2F;&#x2F;ilan.schnell-web.net&#x2F;prog&#x2F;perfect-hash&#x2F;algo.html" rel="nofollow">http:&#x2F;&#x2F;ilan.schnell-web.net&#x2F;prog&#x2F;perfect-hash&#x2F;algo.html</a><p>[2] <a href="http:&#x2F;&#x2F;cmph.sourceforge.net&#x2F;" rel="nofollow">http:&#x2F;&#x2F;cmph.sourceforge.net&#x2F;</a>