{"id":24316359,"url":"https://github.com/stackworx/js-map-workshop","last_synced_at":"2026-04-17T20:31:47.367Z","repository":{"id":125176323,"uuid":"147919375","full_name":"stackworx/js-map-workshop","owner":"stackworx","description":null,"archived":false,"fork":false,"pushed_at":"2018-09-14T12:45:55.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T11:19:17.858Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/stackworx.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":"2018-09-08T09:21:32.000Z","updated_at":"2018-09-14T12:45:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"b8c3ef1b-57be-443b-8a35-b5e38652aaaf","html_url":"https://github.com/stackworx/js-map-workshop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stackworx/js-map-workshop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackworx%2Fjs-map-workshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackworx%2Fjs-map-workshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackworx%2Fjs-map-workshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackworx%2Fjs-map-workshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackworx","download_url":"https://codeload.github.com/stackworx/js-map-workshop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackworx%2Fjs-map-workshop/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31944971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-01-17T12:40:19.695Z","updated_at":"2026-04-17T20:31:47.359Z","avatar_url":"https://github.com/stackworx.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Read Me\n\nThis is a workshop for implementing a hash map in pure javascript.\nIn the interests of simplicty it will only allow string keys\n\n### Algorithmic Complexity\n\nAn important feature of a map is that it usually has an `O(1)` get and `O(k)` get and deletes where `k` is the number of buckets\\*.\n\n(This is not entirely true, its actually only `O(1)` in the average case, aka amortized `O(1)`)\n\nBriefly discuss, linked list as it is used in map\n\n### Hashing\n\nMost map implementations rely on hashing to get good performance.\n\n## Getting Started\n\n```\nyarn install\nyarn test\n```\n\n## Psuedo Code\n\n### 1. Hashing\n\n```\nhashCode(s: string): number {\n  hash = 0\n\n  for c in string s:\n    char = s[i]\n    hash = (hash \u003c\u003c 5) - hash + char\n    hash |= 0\n\n  return hash\n}\n```\n\n### 2. Get Bucket Index\n\n```\ngetBucketIndex(key: string): number {\n  hash = hashCode(key)\n  return hash % this.numBuckets\n}\n```\n\n### 3. Set - Part 1\n\n```\nset(key: string, value: any) {\n  bucketIndex = this.getBucketIndex(key)\n  let head = this.buckets[bucketIndex]\n\n  Loop through the bucket\n  If a matching key is found, exit\n\n  If key is not found, increment the size\n  And create a new HashNode.\n  Prepend this to the start of the linked list\n}\n```\n\n### 4. Get\n\n```\nget(key: string) {\n  bucketIndex = this.getBucketIndex(key)\n  let head = this.buckets[bucketIndex]\n\n  Loop through the bucket\n  If a matching key is found return it\n\n  If key is not found, return undefined\n}\n```\n\n### 5. Clear\n\n```\nclear() {\n  set size to zero\n  reset buckets array\n  reset num buckets\n}\n```\n\n### 6. Delete\n\n```\ndelete(key: string) {\n  bucketIndex = this.getBucketIndex(key)\n  let head = this.buckets[bucketIndex]\n\n  Loop through the bucket and try to find key\n\n  if Key not found, exit\n\n  Decrement size\n  Remove key but cutting it out of the linked list\n}\n```\n\n### 7. Set Part 2 (Expand buckets)\n\n```\nAfter set is complete, check if we need to increase the number of buckets\n\nif (size / numBuckets \u003e= THRESHOLD) {\n  temp = buckets\n  buckets = []\n  numBuckets = numbuckets * 2\n  size = 0\n\n  for (node in temp) {\n\n  }\n  Loop over every node in the temp list and invoke set with the values\n}\n```\n\n## References\n\n- https://en.wikipedia.org/wiki/Hash_table#Choosing_a_hash_function\n\n* https://en.wikipedia.org/wiki/Big_O_notation\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackworx%2Fjs-map-workshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackworx%2Fjs-map-workshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackworx%2Fjs-map-workshop/lists"}