Last active
February 24, 2021 07:52
-
-
Save kiinlam/edbaa52daddd964f4f93bdc676bd9046 to your computer and use it in GitHub Desktop.
time 33 哈希函数
This file contains hidden or 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
/** | |
A string hashing function based on Daniel J. Bernstein's popular 'times 33' hash algorithm. | |
@param {string} text - String to hash | |
@return {number} Resulting number. | |
*/ | |
function hash(text) { | |
'use strict'; | |
var hash = 5381, | |
index = text.length; | |
while (index) { | |
hash = (hash * 33) ^ text.charCodeAt(--index); | |
} | |
return hash >>> 0; | |
} | |
// refer:https://segmentfault.com/a/1190000013132249(纪念司徒正美君) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment