{"id":25490182,"url":"https://github.com/fix2015/hash_table","last_synced_at":"2025-08-09T22:06:40.697Z","repository":{"id":273079648,"uuid":"918648930","full_name":"fix2015/hash_table","owner":"fix2015","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-18T13:54:56.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-02T13:14:19.799Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fix2015.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-18T13:52:13.000Z","updated_at":"2025-01-18T14:41:23.000Z","dependencies_parsed_at":"2025-01-18T15:04:34.182Z","dependency_job_id":"66be647a-29cd-44ff-874d-a0e9cf678990","html_url":"https://github.com/fix2015/hash_table","commit_stats":null,"previous_names":["fix2015/hash_table"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fix2015/hash_table","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fhash_table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fhash_table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fhash_table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fhash_table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fix2015","download_url":"https://codeload.github.com/fix2015/hash_table/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fhash_table/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269644791,"owners_count":24452616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-09T02:00:10.424Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-18T21:27:27.660Z","updated_at":"2025-08-09T22:06:40.643Z","avatar_url":"https://github.com/fix2015.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hash Table Data Structure in JavaScript 🚀  \n\nA simple implementation of the **Hash Table** data structure in JavaScript. This repository demonstrates how to create a hash table class with essential methods and explains its functionality with practical examples.  \n\n---\n\n## What is a Hash Table?  \nA **Hash Table** (or Hash Map) is a data structure that stores key-value pairs. It uses a hash function to compute an index (hash) into an array of buckets or slots, from which the desired value can be found. Hash tables provide fast access to data and are widely used for implementing associative arrays or database indexing.  \n\n---\n\n## Features  \n- **Insert**: Add a key-value pair to the hash table.  \n- **Delete**: Remove a key-value pair from the hash table.  \n- **Search**: Find a value by its key.  \n- **Size**: Get the number of key-value pairs in the table.  \n\n---\n\n## Code Implementation  \n\nHere’s the JavaScript implementation of the hash table:  \n\n```javascript\nclass HashTable {\n    constructor(size = 50) {\n        this.table = new Array(size); // Initialize the hash table with a given size\n    }\n\n    // Hash function to calculate the index\n    hash(key) {\n        let hash = 0;\n        for (let i = 0; i \u003c key.length; i++) {\n            hash = (hash \u003c\u003c 5) + hash + key.charCodeAt(i); // Hashing algorithm\n        }\n        return hash % this.table.length; // Return the index within table size\n    }\n\n    // Insert a key-value pair into the hash table\n    insert(key, value) {\n        const index = this.hash(key);\n        if (!this.table[index]) {\n            this.table[index] = [];\n        }\n        this.table[index].push([key, value]); // Handle collisions by chaining\n    }\n\n    // Delete a key-value pair from the hash table\n    delete(key) {\n        const index = this.hash(key);\n        if (this.table[index]) {\n            this.table[index] = this.table[index].filter(([k, v]) =\u003e k !== key);\n        }\n    }\n\n    // Search for a value by its key\n    search(key) {\n        const index = this.hash(key);\n        if (this.table[index]) {\n            for (let [k, v] of this.table[index]) {\n                if (k === key) {\n                    return v;\n                }\n            }\n        }\n        return null; // Return null if key is not found\n    }\n\n    // Get the size of the hash table\n    size() {\n        let count = 0;\n        for (let bucket of this.table) {\n            if (bucket) {\n                count += bucket.length;\n            }\n        }\n        return count;\n    }\n}\n```\n\n---\n\n## Example Usage  \n\n```javascript\n// Initialize the hash table\nconst hashTable = new HashTable();\n\n// Insert key-value pairs\nhashTable.insert(\"name\", \"John\");\nhashTable.insert(\"age\", 30);\nhashTable.insert(\"city\", \"New York\");\n\n// Search for a value by its key\nconsole.log(hashTable.search(\"name\")); // Output: John\nconsole.log(hashTable.search(\"age\")); // Output: 30\n\n// Delete a key-value pair\nhashTable.delete(\"age\");\nconsole.log(hashTable.search(\"age\")); // Output: null\n\n// Get the size of the hash table\nconsole.log(hashTable.size()); // Output: 2\n```\n\n---\n\n## Real-World Applications  \n1. **Database Indexing**: Used in databases to quickly find records.  \n2. **Caching**: Storing computed results for faster access.  \n3. **Implementing Sets**: Storing unique elements without duplicates.  \n4. **Associative Arrays**: Used in languages like JavaScript and Python to map keys to values.  \n\n---\n\n## TikTok Tutorial 🎥  \nWant to see a quick tutorial on how to build this? Check out this TikTok video:  \n[]()  \n\n---\n\n## How to Run the Code  \n1. Clone the repository:  \n   ```bash\n   git clone https://github.com/your-username/hash-table-data-structure.git\n   cd hash-table-data-structure\n   ```\n2. Open the file `hash-table.js` in your favorite code editor.  \n3. Run the file using Node.js:  \n   ```bash\n   node hash-table.js\n   ```\n\n---\n\n## Contributing  \nContributions are welcome! If you have suggestions or want to add new features, feel free to create a pull request.  \n\n---\n\n## License  \nThis project is licensed under the MIT License.  \n\n---\n\n## Connect with Me:\n- [LinkedIn - Vitalii Semianchuk](https://www.linkedin.com/in/vitalii-semianchuk-9812a786/)\n- [Telegram - @jsmentorfree](https://t.me/jsmentorfree) - We do a lot of free teaching on this channel! Join us to learn and grow in web development.\n- [Tiktok - @jsmentoring](https://www.tiktok.com/@jsmentoring) Everyday new videos\n- [Youtube - @jsmentor-uk](https://www.youtube.com/@jsmentor-uk) Mentor live streams\n- [Dev.to - fix2015](https://dev.to/fix2015) Javascript featured, live, experience but about Hash Table\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffix2015%2Fhash_table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffix2015%2Fhash_table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffix2015%2Fhash_table/lists"}