Skip to content

Instantly share code, notes, and snippets.

Created June 8, 2017 12:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5cf0c8f445cc255d36a6d5b25bbf31f4 to your computer and use it in GitHub Desktop.
Save anonymous/5cf0c8f445cc255d36a6d5b25bbf31f4 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <list>
#include <unordered_map>
class KeyHasher {
public:
std::size_t operator()(const int& k) const {
return k%2;
}
};
int main () {
std::unordered_map<int,int, KeyHasher> mymap;
std::list<int> lints = {66, 81, 33, 21, 99, 96, 60, 17, 28, 22};
mymap.reserve(15);
for(auto v : lints)
mymap.insert({v,v});
unsigned n = mymap.bucket_count();
std::cout << "mymap has " << n << " buckets.\n";
for (unsigned i=0; i<n; ++i) {
std::cout << "bucket #" << i << " contains: ";
for (auto it = mymap.begin(i); it!=mymap.end(i); ++it)
std::cout << "[" << it->first << ":" << it->second << "] ";
std::cout << "\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment