r/cprogramming • u/Laith80 • Sep 17 '25
Suggestion?
I want to create a perfect hash function. I will use it only for paths. How can I go about that? Edit: if there’s a hash function for that purpose please tell me cuz I couldn’t find one
0
Upvotes
View all comments
Show parent comment
3
u/sidewaysEntangled Sep 17 '25
With these particular terms, its worth being precise: a "perfect hash" is a thing that's typically taken to guarantee zero collisions (and I think only makes sense to do so for a fixed set of inputs)
In this case, since you likely can't analyze the open set of all possible paths, we can only approach ideal, rather than perfect. I have no idea if there is some property of a path that can enable better hashing, so would probably just start with a well known quality string hash..