Created
May 6, 2017 08:05
Cheap hash for javascript
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
export default (s)=> { | |
let hash = 0 | |
let strlen = s.length | |
if ( strlen === 0 ) { | |
return hash; | |
} | |
for (let i = 0; i < strlen; i++) { | |
let c = s.charCodeAt(i) | |
hash = ((hash << 5) - hash) + c | |
hash = hash & hash | |
} | |
return hash | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment