Download next.js/packages/next/src/shared/lib/hash.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 866 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/shared/lib/hash.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/shared/lib/hash.ts
-
curl -L -o hash.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/shared/lib/hash.ts
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) | |
| } | |