Re: Combining hash values
Robert Haas <robertmhaas@gmail.com>
From: Robert Haas <robertmhaas@gmail.com>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Greg Stark <stark@mit.edu>, Thomas Munro <thomas.munro@enterprisedb.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>,
Tom Lane <tgl@sss.pgh.pa.us>
Date: 2016-08-01T22:21:15Z
Lists: pgsql-hackers
On Mon, Aug 1, 2016 at 7:24 AM, Dean Rasheed <dean.a.rasheed@gmail.com> wrote: > On 1 August 2016 at 08:19, Greg Stark <stark@mit.edu> wrote: >> Surely combining multiple hashes is the same problem as hashing a block of >> memory? Shouldn't we just use the same algorithm as hash_any()? > > Yes, I imagine that should work well. I suspect that Thomas's proposal > would also probably work well, as would a number of other hashing > algorithms with reasonable pedigree, such as the one used for array > hashing. I don't have any particular preference, but I do know that > what usually turns out to be disastrous is an arbitrary made-up > formula like rotating and xor'ing. The last thing we should attempt to > do is invent our own hashing algorithms. +1. (x << 1) | y isn't the stupidest way of combining hash values anybody's ever invented, but there are surely others that are better. I don't much care whether we adopt Thomas's proposal or Greg's or something else, but I can't see why we'd stick with (x << 1) | y when better approaches are known. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Commits
-
Add a hash_combine function for mixing hash values.
- 0052a0243d9c 11.0 landed