Instantly share code, notes, and snippets.

Embed
What would you like to do?
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