News for hackers. Stuff that matters.
Re:Modern Perfect Hashing by mgaunard on Friday October 24, 2025 @05:12PM (#45699150)
What's most annoying with gperf and similar tools is that they aren't really suited to applications where the set of keys is known at runtime during initialization.
Re:Modern Perfect Hashing by jibal on Friday October 24, 2025 @06:13PM (#45699631)
Re:Modern Perfect Hashing by hinkley on Saturday October 25, 2025 @02:47AM (#45701821)
If I'm understanding this correctly, you're essentially hashing twice. You get a perfect hash on the second hash call, and don't worry about one on the first.

There are other hash tables that use double hashing but they don't guarantee a lack of collisions. They just make them highly improbable.

Re:Modern Perfect Hashing by anitil on Saturday October 25, 2025 @01:08AM (#45701483)
I wrote a python library that would build a perfect hash at run-time, it was basically the stupidest way you could do it - it would shell out to gperf to build the library, compile it to a shared library, then link the entry points in (I think with ctypes? I can't remember).

It was just for fun, but in the end even ignoring the startup costs of all of that, the default performance of python's dictionary was better.

Re:Modern Perfect Hashing by hinkley on Saturday October 25, 2025 @02:44AM (#45701806)
Maybe this is one of those situations where compile time code execution wins out. Instead of needing one solution for runtime and one for a priori knowledge, you just run the runtime code during the build process and Bob's your uncle.
Re:Modern Perfect Hashing by zvr on Saturday October 25, 2025 @05:34AM (#45702513)
I've written code that, during initialization, after all keys have been collected, essentially called gperf to create the lookup function, compiled it, and then dynamically loaded it, so that the (long-running) program would be able to use it.
Re:Modern Perfect Hashing by mgaunard on Saturday October 25, 2025 @05:49AM (#45702575)
That means you need to deploy with a compiler etc., not ideal.
Re:Modern Perfect Hashing by HackerThemAll on Sunday October 26, 2025 @06:43PM (#45715766)
This situation doesn't have ideal solution. You either bundle compiler for the best speed at runtime, or you lose efficiency.
Re:Modern Perfect Hashing by zvr on Wednesday October 29, 2025 @06:30AM (#45744935)
Yes, it was a controlled environment and it was known that there will be gperf and gcc available.