Skip to content

Instantly share code, notes, and snippets.

@codebrainz
Last active July 23, 2018 23:49
Show Gist options
  • Save codebrainz/8ece2a9015a3ed0d260f to your computer and use it in GitHub Desktop.
Save codebrainz/8ece2a9015a3ed0d260f to your computer and use it in GitHub Desktop.
Using std::hash with char* as a C string rather than a pointer.
namespace std
{
template <>
struct hash<char *>
{
size_t operator()(const char *s) const
{
// http://www.cse.yorku.ca/~oz/hash.html
size_t h = 5381;
int c;
while ((c = *s++))
h = ((h << 5) + h) + c;
return h;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment