Welcome to the Hashmap Demo, a super cool JavaScript implementation of a hashmap created for The Odin Project. This is a showcase of data structures done right, built from the ground up with skill and a dash of coding finesse!
Get ready to explore a custom-built hashmap that efficiently handles key functionalities like setting, getting, and removing key-value pairs, with collision handling done right.
- Custom Hash Function: Crafted for fair distribution of key-value pairs.
- Collision Handling with Linked Lists: Smartly handles data collisions.
- Dynamic Resizing: Scales beautifully as your data grows.
- Iterator Functionality: Traverse keys, values, and entries with ease.
- Essential Operations: Set, get, remove, and check keys in a flash!
Ready to dive in? Here's how to get this hashmap up and running on your local machine:
Ensure you have Node.js installed to run this project.
-
Clone the Repository:
git clone https://github.com/AntonHarbers/hashmap-demo cd hashmap-demo
-
Run the Demo:
node script.js
And that's it! You're now experiencing the power of this custom hashmap. Feel free to tweak the script, hashmap or linked list for your custom usage
Here's how to use the hashmap:
const { HashMap } = require('./HashMap');
const myMap = new HashMap(20); // Initialize with desired capacity
myMap.set('key1', 'value1');
myMap.set('key2', 'value2');
const value = myMap.get('key1'); // returns 'value1'
if (myMap.has('key1')) {
console.log('Key1 exists!');
}
myMap.remove('key1'); // Key1 is now gone!
for (const keyValue of myMap.entries()) {
console.log(keyValue); // Logs each key-value pair
}
The HashMap class includes these methods:
set(key, value)
: Add or update a key-value pair.get(key)
: Retrieve the value for a given key.has(key)
: Check if a key is in the hashmap.remove(key)
: Remove a key-value pair.length()
: Get the number of pairs in the hashmap.keys()
: List all keys.values()
: List all values.entries()
: List all key-value pairs.clear()
: Clear the hashmap.
While contributions are currently not welcome as this is a personal portfolio project, feel free to clone or fork it for your own experiments!
This project is released under the MIT License.
- A big thank you to The Odin Project for the inspiration behind this build.
- Cheers to the JavaScript community for making learning and coding a fun journey.