Hashing

function createKey(word) {    value = 0
for(letter of word) {
value += word.charCodeAt(0)
}
return value
}
function createTable(arr) {
let table = [...Array(Math.floor(arr.length * 1.3))].map(() => false)
for(word of arr) {
key = createKey(word)
while(table[key % Math.floor(arr.length * 1.3)] != word) {
if(!table[key % Math.floor(arr.length * 1.3)]) {
table[key % Math.floor(arr.length * 1.3)] = word
} else {
key += 1
}
}
}
return table
}
function createTable(arr) {
let table = [...Array(10].map(() => false)
for(word of arr) {
key = createKey(word) % 10
spot = table[key]
if(!spot) {
table[key] = Node.new()
table[key].data = word
} else {
while(spot.next){
spot = spot.next
}
spot.next = Node.new()
spot.next.data = word
}
}
return table
}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Create an SSL VPN server on Alibaba Cloud in 15 Minutes

10+ Best Ansible Tutorials For Beginners — Learn Ansible Online

Introduction to No Sql Database

How to work with Hive tables with a lot of partitions from Spark

Enable Touchpad Gestures on Linux

Encrypt and Decrypt Files using Python — Python Programming

SessionStack’s Year in Review: What We Shipped, Where We Hung Out, and Who We Talked to

What Is Private Cloud?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aidanmc

Aidanmc

More from Medium

Intel Journey

JWS Signature Validation

Finding Maximum and Minimum Elements in An Array

PANN memory results.