2025-04-01 10:38:02 +09:00

13 lines
285 B
TypeScript

/**
* Hashes a string using the DJB2 algorithm.
*/
export function djb2Hash(str: string): number {
let hash = 5381;
for (let i = 0; i < str.length; i++) {
hash = (hash * 33) ^ str.charCodeAt(i);
}
return hash >>> 0; // Ensure the result is an unsigned 32-bit integer
}