Skip to content

Instantly share code, notes, and snippets.

@daniel-abramov
Created June 19, 2016 16:57
Show Gist options
  • Save daniel-abramov/501c46898522bd54bbdabefd572c00db to your computer and use it in GitHub Desktop.
Save daniel-abramov/501c46898522bd54bbdabefd572c00db to your computer and use it in GitHub Desktop.
FNV hash for strings
uint64_t fnvhash(const char* data, size_t size) {
uint64_t hsh = 14695981039346656037L;
for (size_t i = 0; i < size; ++i) {
hsh = (hsh * 1099511628211L) ^ (uint64_t)(data[i]);
}
return hsh;
}
// Calculating the hash for QString
template <>
struct hash<QString> {
size_t operator() (const QString& s) {
return fnvhash(s.data(), s.size());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment