Here is the hashcode (written in javascript), source: https://github.com/m3talstorm/hashcode/blob/master/lib/hashcode.js:
const hash = (string) => {
let hash = 0
string = string.toString()
for(let i = 0; i < string.length; i++) {
hash = (((hash << 5) - hash) + string.charCodeAt(i)) & 0xFFFFFFFF
}
return hash
}
I don't understand the for loop.
1) Why is the developer shifting the hash variable 5 bits to the left and subtracting the hash value from the result?
2) Why is the developer using "&0xFFFFFFFF"? Doesn't any number ANDed with that just give the number itself?
I have seen it in two more examples, so I am assuming that this is a decently popular hashcode implementation. If so I'd like to learn it.