Skip to content

Instantly share code, notes, and snippets.

@romanbsd
Created June 27, 2018 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romanbsd/9df48b74b618c8092f90c1a3c43315c4 to your computer and use it in GitHub Desktop.
Save romanbsd/9df48b74b618c8092f90c1a3c43315c4 to your computer and use it in GitHub Desktop.
#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