'use strict';

/**
 * 获取字符串的哈希值
 * @param {string} string
 * @returns
 */
function getStringHash(string) {
  var hash = 0;
  var i = -1;

  var _char;

  if (string.length === 0) return hash;

  // Convert to 32bit integer
  while (++i < string.length) {
    _char = string.charCodeAt(i);
    hash = (hash << 5) - hash + _char;
    hash |= 0;
  }

  return Math.abs(hash) * 10 + string.length % 10;
}

module.exports = getStringHash;
