https://github.com/sreddy-96/top-hash-table
The Odin Project - Hash Tables project
https://github.com/sreddy-96/top-hash-table
hash hash-map hash-table hashing javascript
Last synced: over 1 year ago
JSON representation
The Odin Project - Hash Tables project
- Host: GitHub
- URL: https://github.com/sreddy-96/top-hash-table
- Owner: SReddy-96
- Created: 2024-07-16T08:28:56.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-17T00:36:50.000Z (almost 2 years ago)
- Last Synced: 2025-01-22T09:48:33.174Z (over 1 year ago)
- Topics: hash, hash-map, hash-table, hashing, javascript
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hash Tables Implementation - The Odin Project
## Project Overview
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.
## Key Features
- 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
## Core Functionalities
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 exists
- `get(key)`: Retrieve the value associated with a key (Hash Map only)
- `remove(key)`: Delete a key-value pair
- `length()`: Return the number of stored elements
- `clear()`: Remove all entries
- `keys()`: Return an array of all keys
- `values()`: Return an array of all values (Hash Map only)
- `entries()`: Return an array of key-value pairs (Hash Map only)
## Technical Highlights
- 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
## Challenges and Solutions
1. **Efficient Hashing**: Implemented a hash function using prime numbers and modulo operation to distribute keys evenly across buckets.
2. **Collision Handling**: Utilized linked lists within buckets to manage multiple entries with the same hash.
3. **Dynamic Resizing**: Implemented a `_resize` method to increase bucket count when the load factor exceeds a threshold, maintaining performance as the data structure grows.
## Skills Developed
- 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
## Reflections
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.
## How to Use
1. Clone the repository:
```
git clone https://github.com/SReddy-96/TOP-hash-table.git
```
2. Navigate to the project directory:
```
cd hash-table
```
3. 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!