Hash Table

Developer
Size
1,783 Kb
Views
28,336

How do I make an hash table?

What is a hash table? How do you make a hash table? This script and codes were developed by Beau Carnes on 13 September 2022, Tuesday.

Hash Table Previews

Hash Table - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Hash Table</title>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>

Hash Table - Script Codes JS Codes

/* Hash Table */
var hash = (string, max) => { var hash = 0; for (var i = 0; i < string.length; i++) { hash += string.charCodeAt(i); } return hash % max;
};
let HashTable = function() { let storage = []; const storageLimit = 14; this.print = function() { console.log(storage) } this.add = function(key, value) { var index = hash(key, storageLimit); if (storage[index] === undefined) { storage[index] = [ [key, value] ]; } else { var inserted = false; for (var i = 0; i < storage[index].length; i++) { if (storage[index][i][0] === key) { storage[index][i][1] = value; inserted = true; } } if (inserted === false) { storage[index].push([key, value]); } } }; this.remove = function(key) { var index = hash(key, storageLimit); if (storage[index].length === 1 && storage[index][0][0] === key) { delete storage[index]; } else { for (var i = 0; i < storage[index].length; i++) { if (storage[index][i][0] === key) { delete storage[index][i]; } } } }; this.lookup = function(key) { var index = hash(key, storageLimit); if (storage[index] === undefined) { return undefined; } else { for (var i = 0; i < storage[index].length; i++) { if (storage[index][i][0] === key) { return storage[index][i][1]; } } } };
};
console.log(hash('quincy', 10))
let ht = new HashTable();
ht.add('beau', 'person');
ht.add('fido', 'dog');
ht.add('rex', 'dinosour');
ht.add('tux', 'penguin')
console.log(ht.lookup('tux'))
ht.print();
Hash Table - Script Codes
Hash Table - Script Codes
Home Page Home
Developer Beau Carnes
Username beaucarnes
Uploaded September 13, 2022
Rating 3
Size 1,783 Kb
Views 28,336
Do you need developer help for Hash Table?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Beau Carnes (beaucarnes) Script Codes
Create amazing Facebook ads with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!