/* We demonstrate how to nest hash tables within one another, to store * unstructured data, kind of like JSON. There's still the limitation that it's * statically typed. */ #include #include #include #include #include #include void test_with_cuckuoo_hash() { typedef libcuckoo::cuckoohash_map InnerTable; typedef libcuckoo::cuckoohash_map> OuterTable; OuterTable tbl; tbl.reserve(5000000); for(int i = 1000000; i < 6000000; ++ i) { std::string outer_key{std::to_string(i)}; std::string inner_key{std::to_string(i)}; std::string inner_val{std::to_string(i)}; tbl.insert(outer_key, std::unique_ptr(new InnerTable)); tbl.update_fn(outer_key, [&](std::unique_ptr &innerTbl) { innerTbl->reserve(4); innerTbl->insert(inner_key, inner_val); }); } std::cout << "count: " << tbl.size() << std::endl; } void test_with_unordered_map() { typedef std::unordered_map InnerTable; typedef std::unordered_map> OuterTable; OuterTable tbl; for(int i = 1000000; i < 6000000; ++ i) { std::string outer_key{std::to_string(i)}; std::string inner_key{std::to_string(i)}; std::string inner_val{std::to_string(i)}; std::unique_ptr inner_tbl = std::make_unique(); inner_tbl->insert({inner_key, inner_val}); tbl.insert({outer_key, std::move(inner_tbl)}); } std::cout << "count: " << tbl.size() << std::endl; } int main() { //test_with_cuckuoo_hash(); //TAKING MORE THAN 64 GB, STILL COULDNT COMPLETE test_with_unordered_map(); //TAKING 1.5 GB return 0; }