Created
June 27, 2018 10:39
-
-
Save romanbsd/9df48b74b618c8092f90c1a3c43315c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __H_CSTRMAP | |
#define __H_CSTRMAP | |
#include <cstring> | |
#include <unordered_map> | |
struct hash_c_string { | |
void hash_combine(size_t &seed, const char &v) const { | |
seed ^= v + 0x9e3779b9 + (seed << 6) + (seed >> 2); | |
} | |
std::size_t operator()(char const *p) const { | |
size_t hash = 0; | |
for (; *p; ++p) { | |
hash_combine(hash, *p); | |
} | |
return hash; | |
} | |
}; | |
struct comp_c_string { | |
bool operator()(char const *p1, char const *p2) const { | |
return strcmp(p1, p2) == 0; | |
} | |
}; | |
template <typename T> | |
class CStrMap : public std::unordered_map<const char *, T, hash_c_string, comp_c_string> { | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment