Live data from Hacker News

Fibonacci Hashing: The Optimization That the World Forgot

probablydance.com

11–20 of 30 posts

Re: Fibonacci Hashing: The Optimization That the World Forgot

#12

To summarize: multiplication hashes are inferior but when used with the golden ratio derived integer, they are actually superior

No, plenty of systems use other factors. The golden ratio has some nice properties, but it's not essential.

Re: Fibonacci Hashing: The Optimization That the World Forgot

#13
post #7

I opened this post in a tab 3 days ago, but now it says "5 hours ago". Someone is playing around.

I h8 it when thir teens get all cheeky like that. Hopefully they'll have matured a bit by 21. Edit: it seems people don't like my Fibonacci joke. I thought I had this kind of thing figured out by 34.

maybe they are confused because they never heard of mathematical operation of maturing.

Re: Fibonacci Hashing: The Optimization That the World Forgot

#15
The Fibonacci series, as fascinating as its name, the origin of the spiral in nature, and the Debian logo, ever-present in computing. The algorithm is surely better as the author says, but most of the time we use what's available. Perhaps the Python, Golang, and JS core programmers could review it.

Re: Fibonacci Hashing: The Optimization That the World Forgot

#16

To summarize: multiplication hashes are inferior but when used with the golden ratio derived integer, they are actually superior

Poor summary.

Better summary. Fibonacci hashing isn't a great hash function, but it is a really good solution to mapping large integers to small integers. Using it for that doubles the speed of hashing in practice.

Re: Fibonacci Hashing: The Optimization That the World Forgot

#17
I think the author has misunderstood things here.

This technique is orthogonal to integer mod. Indeed the author multiplies by their magic constant and then does an integer mod to map into their hashtable's buckets.

This technique is actually just applying a fast integer hash on the input keys to the hashtable before mapping the keys to buckets. You can then map to buckets however you want.

The additional hash is useful if and only if the input hash function for your table's keys doesn't appear to be a random function, i.e. it doesn't mix its bits for whatever reason. If your input hash functions are indeed random then this is a (small but perhaps measurable) waste of time.

Using prime-numbered table sizes is another way to accomplish basically the same thing. Dividing the input hash key by a prime forces you to look at all the bits of the input. In practice these are written as division by a constant, so they use multiplies and shifts. It's basically a hash function. (Though I'd use multiply by a magic number over divide by a prime, mul alone should be faster.)

Relatedly see this post by Daniel Lemire about an alternative to integer mod, https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-... which is interesting if your number of buckets is not a power of 2 for some reason.

Re: Fibonacci Hashing: The Optimization That the World Forgot

#19
post #17

I think the author has misunderstood things here. This technique is orthogonal to integer mod. Indeed the author multiplies by their magic constant and then does an integer mod to map into their hashtable's buckets. This technique is actually just applying a fast integer hash on the input keys to the hashtable before mapping the keys to buckets. You can then map to buckets however you want. The additional hash is use…

I think the post talks about exactly this? The method is combining hashing the keys and finding a position in the target range. There's a bit where he talks about how Knuth uses the term 'hash function' as the combination of these two operations, while modern texts look at the two operations in isolation.

So maybe one way of looking at this is as an efficient fusion operation, which doesn't look special when you look at the ops in isolation, but combine to something that is both fast and advised problems with input patterns.

Post reply on HN