// https://www.partow.net/programming/hashfunctions/index.html#DJBHashFunction
// https://theartincode.stanis.me/008-djb2/
export function djb2Hash(str: string) {
  let hash = 5381;
  for (let i = 0; i < str.length; i++) {
    hash = (hash << 5) + hash + str.charCodeAt(i);
  }
  return hash;
}

// Returns a 32-bit unsigned integer hash from a string using the djb2 algorithm.
export function djb2HashUint32(str: string) {
  const hash = djb2Hash(str);
  return hash >>> 0;
}
