From cc82fd2ae443bebfd23cbe7747035cb6ddd62e42 Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Tue, 19 Jul 2022 20:45:54 -0400 Subject: [PATCH] forgot to add new file --- examples/basic.cc | 61 ++++++++++++++++++++++++++++------------------- examples/hash.cc | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 24 deletions(-) mode change 100644 => 100755 examples/basic.cc create mode 100755 examples/hash.cc diff --git a/examples/basic.cc b/examples/basic.cc old mode 100644 new mode 100755 index 2b7f050..0cfb186 --- a/examples/basic.cc +++ b/examples/basic.cc @@ -1,28 +1,41 @@ -#include +#include #include -#include +#include +#include "parallel_hashmap/phmap.h" + + +int main() { + phmap::flat_hash_map> mymap; + + //initialize mymap + mymap["hitF"].push_back("hitF"); + mymap["hitB"].push_back("hitB"); + mymap["idleF"].push_back("idleF"); + mymap["idleB"].push_back("idleB"); + mymap["walkF"].push_back("walkF"); + mymap["walkB"].push_back("walkB"); + mymap["dyingF"].push_back("dyingF"); + mymap["dyingB"].push_back("dyingB"); + mymap["attackF"].push_back("attackF"); + mymap["attackB"].push_back("attackB"); + + //set fallbacks + mymap["downB"] = mymap["idleB"]; + mymap["downF"] = mymap["idleF"]; + mymap["hit_upF"] = mymap["idleF"]; + mymap["hit_upB"] = mymap["idleB"]; + mymap["weakF"] = mymap["idleF"]; + mymap["weakB"] = mymap["idleB"]; + + //print map + for(auto& element : mymap) { + std::cout << element.first << ": "; + for(auto& inner : element.second) { + std::cout << inner; + } + std::cout << std::endl; + } + -using phmap::flat_hash_map; - -int main() -{ - // Create an unordered_map of three strings (that map to strings) - flat_hash_map email = - { - { "tom", "tom@gmail.com"}, - { "jeff", "jk@gmail.com"}, - { "jim", "jimg@microsoft.com"} - }; - - // Iterate and print keys and values - for (const auto& n : email) - std::cout << n.first << "'s email is: " << n.second << "\n"; - - // Add a new entry - email["bill"] = "bg@whatever.com"; - - // and print it - std::cout << "bill's email is: " << email["bill"] << "\n"; - return 0; } diff --git a/examples/hash.cc b/examples/hash.cc new file mode 100755 index 0000000..c33afec --- /dev/null +++ b/examples/hash.cc @@ -0,0 +1,46 @@ +#include // minimal header providing phmap::HashState() +#include +#include +#include +#include +#include +#include +#include + +using std::string; +using std::tuple; +using std::pair; + +using groupid_t = std::array; + +namespace std +{ + template<> struct hash + { +#if 0 + std::size_t operator()(groupid_t const &g) const + { + const std::string_view bv{reinterpret_cast(g.data()), sizeof(g)}; + return std::hash()(bv); + } +#else + std::size_t operator()(groupid_t const &g) const + { + return phmap::Hash()(std::tuple_cat(g)); + } +#endif + }; +} + +int main() +{ + std::vector groups = { + {17, 75, 82, 66}, + {22, 88, 54, 42}, + {11, 55, 77, 99} }; + + for (const auto &g : groups) + std::cout << std::hash()(g) << '\n'; + + return 0; +}