A complete HashMap implementation from scratch using JavaScript, featuring collision handling through linked lists and dynamic resizing. Built as part of The Odin Project's JavaScript course to understand how hash tables work under the hood.
- Complete HashMap Implementation - All essential hash map operations (set, get, has, remove, etc.)
- Collision Resolution - Uses linked lists (separate chaining) to handle hash collisions
- Dynamic Resizing - Automatically doubles capacity when load factor reaches 0.75
- Bounds Protection - Prevents out-of-bounds array access
- Integer Overflow Protection - Modulo operator applied during hashing to handle long keys
- Comprehensive Testing - Includes test suite to verify all functionality
Want to run this project locally? Here's how:
- Node.js (v14 or higher)
- Basic understanding of data structures (linked lists, arrays)
- Clone the repository:
git clone https://github.com/MatimotTheTimoters/hashmap.git
cd hashmap- Ensure your package.json has ES modules enabled:
{
"type": "module"
}Run the test suite to see the HashMap in action:
node test.jsThe test file demonstrates:
- Populating the hash map to full capacity
- Triggering automatic growth
- Overwriting existing values
- All CRUD operations (Create, Read, Update, Delete)
- Retrieving keys, values, and entries
- Using
load factorandcapacityto check if the list needs to grow - How to hash a given key using modulo (
%) - Implementing a linked list within each bucket/index of the hash table/key value pair array
- I was able to practice traversing a linked list again by going through all nodes
- Accessing the key/value from each node within a given bucket
- Using two pointer (
currentandprevious) to remove a node by updating theirpointerproperty - Dynamically increasing the size of the list via
growfunction
Built with 💡 and ☕ as part of my journey through The Odin Project