mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-29 08:34:39 +08:00
forgot to add new file
This commit is contained in:
Regular → Executable
+37
-24
@@ -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;
|
||||
}
|
||||
|
||||
Executable
+46
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user