As AndrewTomazos-Fathomling said, it is not possible to make a secure hash in 64 bits, so if this is your intention, then my STOP advice is to take a book and read about cryptographically secure hashing.
If you do not plan to use this as a safe hash, and you do not need collisions or attacks, then the answer that he gave you works fine, and you can change the prime numbers P1 and P2 if necessary. I will give you another alternative that allows you to flag hashing and mix things more.
// Disclaimer: I make no claims about the quality of this particular hash - it // certainly not a cryptographically secure hash, nor should it *ever* be // construed as such. unsigned long long quickhash64(const char *str, unsigned long long mix = 0) { // set 'mix' to some value other than zero if you want a tagged hash const unsigned long long mulp = 2654435789; mix ^= 104395301; while(*str) mix += (*str++ * mulp) ^ (mix >> 23); return mix ^ (mix << 37); }
source share