var loseloseHashCode = function (key) {
var hash = 0;
for (var i = 0; i < key.length; iPP) {
hash += key.charCodeAt(i);
}
return hash % 37;
};
this.put = function(key, value) {
var position = loseloseHashCode(key); //{5}
console.log(position + " - " + key); //{6}
table[position] = value; //{7}
};
question: seeing the last return hash% 37
of the hash function in a book, I tested that it would be overwritten. For example, when key="Abc"
and key="fbc"
, because the sum of the ASCII code values of Abc is 262 and the sum of ASCII values of fbc is 299. The two of them have their own Mod37=3. So a value is inserted in the position=3 position, and the result is an override. The book is for relatively small values, but this will produce coverage, ah, is this the original meaning of the hash function?