forgot to add new file

This commit is contained in:
greg7mdp
2022-07-19 20:45:54 -04:00
parent 1249057455
commit cc82fd2ae4
2 changed files with 83 additions and 24 deletions
Regular → Executable
+37 -24
View File
@@ -1,28 +1,41 @@
#include <iostream>
#include <vector>
#include <string>
#include <parallel_hashmap/phmap.h>
#include <iostream>
#include "parallel_hashmap/phmap.h"
int main() {
phmap::flat_hash_map<std::string, std::vector<std::string>> 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<std::string, std::string> 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;
}
+46
View File
@@ -0,0 +1,46 @@
#include <parallel_hashmap/phmap_utils.h> // minimal header providing phmap::HashState()
#include <string>
#include <utility>
#include <tuple>
#include <vector>
#include <array>
#include <string_view>
#include <iostream>
using std::string;
using std::tuple;
using std::pair;
using groupid_t = std::array<uint16_t, 4>;
namespace std
{
template<> struct hash<groupid_t>
{
#if 0
std::size_t operator()(groupid_t const &g) const
{
const std::string_view bv{reinterpret_cast<const char*>(g.data()), sizeof(g)};
return std::hash<std::string_view>()(bv);
}
#else
std::size_t operator()(groupid_t const &g) const
{
return phmap::Hash<decltype(std::tuple_cat(g))>()(std::tuple_cat(g));
}
#endif
};
}
int main()
{
std::vector<groupid_t> groups = {
{17, 75, 82, 66},
{22, 88, 54, 42},
{11, 55, 77, 99} };
for (const auto &g : groups)
std::cout << std::hash<groupid_t>()(g) << '\n';
return 0;
}