javascript - what is possibility of collision in djb2 function? -


i trying generate unique id using djb2 hash function string

"114.143.227.82mozilla/5.0 (windows nt 6.3; wow64; rv:38.0) gecko/20100101 firefox/38.0"

what possibility of collision using algorithm given below in javascript.

string.prototype.hashcode = function(){ var hash = 5381; if (this.length === 0) return hash; (var = 0; < this.length; i++) { var character = this.charcodeat(i); hash = (( hash << 5 ) + hash ) ^ character; } return hash; }

usage:

var hash = new string("114.143.227.82"+navigator.useragent).hashcode();

alert(hash);

reference:

http://www.cse.yorku.ca/~oz/hash.html

for above string getting -ve integer value. how return +ve integer types of string?

i got solution after modifying above code.

string.prototype.hashcode = function(){ var hash = 5381; if (this.length === 0) return hash; (var = 0; < this.length; i++) { var character = this.charcodeat(i);
hash = hash * 33 ^character; } return hash >>>0; }


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -