Hash Table
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 - 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();
Developer | Beau Carnes |
Username | beaucarnes |
Uploaded | September 13, 2022 |
Rating | 3 |
Size | 1,783 Kb |
Views | 28,336 |
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!
Name | Size |
Promises | 1,845 Kb |
A Pen by Beau Carnes | 2,118 Kb |
Notifications | 1,672 Kb |
Heaps | 1,976 Kb |
Internet Dungeon Game | 12,502 Kb |
Camper Leaderboard | 4,550 Kb |
Linked List | 1,977 Kb |
Wikipedia Viewer | 2,320 Kb |
Sets | 1,920 Kb |
Array iteration | 1,663 Kb |
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!
Name | Username | Size |
Project_one | MOHIM | 9,592 Kb |
A Pen by John Malc | F789gh | 1,420 Kb |
Sidebar Thing | Jonambas | 2,779 Kb |
CSS Bot Confusion | Jpod | 3,456 Kb |
Polo, the flying squirrel | Agbales | 2,445 Kb |
Material design buttons | Fischaela | 4,381 Kb |
AngularJS Datalist Directive | M-e-conroy | 2,366 Kb |
Google Maps API Ground Overlay | Boycetrus | 2,961 Kb |
Virtual vinyl | Davidpanik | 3,474 Kb |
Twinner Spinner II | Katydecorah | 2,974 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!