Last active
July 23, 2018 23:49
-
-
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.
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
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