silverwolf-x's picture
download
raw
866 Bytes
// 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.
export function djb2Hash(str: string) {
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
}
export function hexHash(str: string) {
return djb2Hash(str).toString(36).slice(0, 5)
}

Xet Storage Details

Size:
866 Bytes
·
Xet hash:
3f15cb275ba549aa604daa2f5d62622af52e484e31044022d1dc3571ea8280f3

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.