Skip to content

Instantly share code, notes, and snippets.

@agasiev
Created December 1, 2012 12:30
Show Gist options
  • Save agasiev/4182011 to your computer and use it in GitHub Desktop.
Save agasiev/4182011 to your computer and use it in GitHub Desktop.
Simple 64 bit string hash
uint64_t str_hash1(std::string str) {
uint64_t result = 0;
uint64_t base = 53;
uint64_t base_pow = 1;
for_each(str.begin(), str.end(), [&](char c) {
result += (c - 'a' + 1) * base_pow; base_pow *= base;
});
return result;
}
int main()
{
cout << str_hash1("aaaa") << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment