This project involves implementing custom Hash Map and Hash Set data structures in JavaScript. The goal is to create efficient hash-based data structures that can store and retrieve data quickly, while handling collisions effectively.
- Custom hash function for optimal bucket distribution
- Collision handling using linked lists
- Separate implementations for Hash Map (key-value pairs) and Hash Set (unique keys)
- Dynamic resizing to maintain performance as the data structure grows
Both Hash Map and Hash Set implementations include the following methods:
set(key, value)
: Add or update a key-value pair (Hash Map only)has(key)
: Check if a key existsget(key)
: Retrieve the value associated with a key (Hash Map only)remove(key)
: Delete a key-value pairlength()
: Return the number of stored elementsclear()
: Remove all entrieskeys()
: Return an array of all keysvalues()
: Return an array of all values (Hash Map only)entries()
: Return an array of key-value pairs (Hash Map only)
- Prime number-based hash function to minimize collisions
- Use of linked lists for efficient collision resolution
- Constant time O(1) complexity for basic operations
- Automatic resizing based on load factor to maintain performance
- Efficient Hashing: Implemented a hash function using prime numbers and modulo operation to distribute keys evenly across buckets.
- Collision Handling: Utilized linked lists within buckets to manage multiple entries with the same hash.
- Dynamic Resizing: Implemented a
_resize
method to increase bucket count when the load factor exceeds a threshold, maintaining performance as the data structure grows.
- Deep understanding of hash table internals
- Improved problem-solving skills in handling edge cases and collisions
- Enhanced proficiency in JavaScript, particularly with array operations and object-oriented programming
This project provided valuable insights into the inner workings of hash-based data structures. It highlighted the importance of efficient hashing and collision resolution in maintaining constant-time operations. The implementation of dynamic resizing demonstrated the trade-off between memory usage and performance in data structure design.
-
Clone the repository:
git clone https://github.com/SReddy-96/TOP-hash-table.git
-
Navigate to the project directory:
cd hash-table
-
Run the script (if using Node.js):
node index.js
Feel free to explore the code and test the various methods implemented in this Hash Table project!