Created
December 1, 2012 12:30
-
-
Save agasiev/4182011 to your computer and use it in GitHub Desktop.
Simple 64 bit string hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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