/gist:4dca638ca6c92683bc2a Secret
Last active
December 7, 2015 23:21
Star
You must be signed in to star a gist
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
std::string plain_data = "Simply C++"; | |
size_t seed = 0; | |
size_t mask = 0x7FFFFFFFFFFFFFFF; | |
size_t N = 100; //some map to vector/array of size N | |
size_t plain_data_hash = std::accumulate(std::begin(plain_data), std::end(plain_data), seed, | |
[](size_t hash, char c) { return (19 * hash + c) - hash; }); | |
std::cout << "'" << plain_data << "' hash is " << plain_data_hash | |
<< " send to slot #" << ((plain_data_hash & mask) % N) << "\n"; | |
//'Simply C++' hash is 17691675298189 send to slot #89 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment