functionbetterHash(data) { const H = 37 var total = 0 for (var i = 0; i < data.length; i++) { total += H * total + data.charCodeAt(i) } total = total % this.table.length if (total < 0) { total += this.table.length - 1 } console.log(total) }
functionsimpleHash(data) { var total = 0 for (var i = 0; i < data.length; i++) { total += data.charCodeAt(i) } return total % this.table.length }
functionbetterHash(data) { const H = 47 var total = 0 for (var i = 0; i < data.length; i++) { total += H * total + data.charCodeAt(i) } total = total % this.table.length if (total < 0) { total += this.table.length - 1 } return total
}
functionshowDistro() { for (var i = 0; i < this.table.length; i++) { if (this.table[i] !== undefined) { console.log(i + ' : ' + this.table[i]) } } }
functionput(data) { var pos = this.betterHash(data) this.table[pos] = data }
functionbuildChains() { for (var i = 0; i < this.table.length; i++) { this.table[i] = newArray() } }
functionbetterHash(data) { const H = 47 var total = 0 for (var i = 0; i < data.length; i++) { total += H * total + data.charCodeAt(i) } total = total % this.table.length if (total < 0) { total += this.table.length - 1 } // console.log('total data:', total, data) return total
}
functionshowDistro() { for (var i = 0; i < this.table.length; i++) { if (this.table[i].length > 0) { console.log(i + ' : ' + this.table[i]) } } }
functionput(data) { var pos = this.betterHash(data) var index = 0
while (this.table[pos][index] != undefined) { index++ } this.table[pos][index] = data
functionbetterHash (data) { const H = 47 var total = 0 for (var i = 0; i < data.length; i++) { total += H * total + data.charCodeAt(i) } total = total % this.table.length if (total < 0) { total += this.table.length - 1 } // console.log('total data:', total, data) return total }
functionshowDistro () { for (var i = 0; i < this.table.length; i++) { if (this.table[i]) { console.log(i + ' : ' + this.table[i]) } } }
functionput (data) { var pos = this.betterHash(data) while (this.table[pos] != undefined) { pos++ } this.table[pos] = data }