Skip to content

Instantly share code, notes, and snippets.

@rorydriscoll
Created March 1, 2012 01:48
Show Gist options
  • Save rorydriscoll/1946538 to your computer and use it in GitHub Desktop.
Save rorydriscoll/1946538 to your computer and use it in GitHub Desktop.
String hash
template<unsigned int N, unsigned int I>
struct FnvHash
{
__forceinline static uint32 Hash(const char (&text)[N])
{
return (FnvHash<N, I - 1>::Hash(text) ^ text[I - 1]) * 16777619u;
}
};
template<unsigned int N>
struct FnvHash<N, 1>
{
__forceinline static uint32 Hash(const char (&text)[N])
{
return (2166136261u ^ text[0]) * 16777619u;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment