Skip to content

Instantly share code, notes, and snippets.

@Marc-B-Reynolds
Last active February 23, 2016 10:03
Show Gist options
  • Save Marc-B-Reynolds/5a939f71fc7237c7af63 to your computer and use it in GitHub Desktop.
Save Marc-B-Reynolds/5a939f71fc7237c7af63 to your computer and use it in GitHub Desktop.
An example 2D hash function based on Weyl generators
// 32-bit example...same holds for 64-bit
uint32_t hash(uint32_t x, uint32_t y)
{
// line = dependency
x *= 0x3504f333; y *= 0xf1bbcdcb; // 1: scaled & rounded to odd (just from mollwollfumble's example)
x ^= y; // 2: cheap combine on the two dimensions (2-adic op on purpose)
x *= 741103597; // 3: MLCG constant of good merit
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment