Javascript String GetHashCode()

Description

Javascript String GetHashCode()

String.prototype.GetHashCode = function () {
  var h = 0;//from   ww  w . ja  v a2  s .  c om

  for (var i = 0; i < this.length; i++) {
    h = ((h << 5) - h + this.charCodeAt(i)) & ~0;
  }

  return h;
};

Javascript String getHashCode()

String.prototype.getHashCode = function() {
    var hash = 0;
    if (this.length == 0) return hash;
    for (var i = 0; i < this.length; i++) {
        hash = this.charCodeAt(i) + ((hash << 5) - hash);
        hash = hash & hash; // Convert to 32bit integer
    }/*from   w w w . ja va 2 s.com*/
    return hash;
};



PreviousNext

Related