next
Version:
The React Framework
42 lines (41 loc) • 1.33 kB
JavaScript
// http://www.cse.yorku.ca/~oz/hash.html
// More specifically, 32-bit hash via djbxor
// (ref: https://gist.github.com/eplawless/52813b1d8ad9af510d85?permalink_comment_id=3367765#gistcomment-3367765)
// This is due to number type differences between rust for turbopack to js number types,
// where rust does not have easy way to repreesnt js's 53-bit float number type for the matching
// overflow behavior. This is more `correct` in terms of having canonical hash across different runtime / implementation
// as can gaurantee determinstic output from 32bit hash.
;
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
djb2Hash: null,
hexHash: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
djb2Hash: function() {
return djb2Hash;
},
hexHash: function() {
return hexHash;
}
});
function djb2Hash(str) {
let hash = 5381;
for(let i = 0; i < str.length; i++){
const char = str.charCodeAt(i);
hash = (hash << 5) + hash + char & 0xffffffff;
}
return hash >>> 0;
}
function hexHash(str) {
return djb2Hash(str).toString(36).slice(0, 5);
}
//# sourceMappingURL=hash.js.map