Skip to content

Instantly share code, notes, and snippets.

@fabiogaluppo
Last active December 7, 2015 23:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fabiogaluppo/4dca638ca6c92683bc2a to your computer and use it in GitHub Desktop.
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