{"action":"created","comment":{"url":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls/comments/30951769","id":30951769,"diff_hunk":"@@ -41,25 +48,71 @@\n \n     for (i = 0; i < str.length; i += 1) {\n       character = str.charCodeAt(i);\n+      /*jshint -W016 */\n       hashCode = ((hashCode << 5) - hashCode) + character;\n       hashCode = hashCode & hashCode;\n+      /*jshint -W016 */\n     }\n \n     return hashCode;\n   };\n \n-  exports.HashTable.prototype.put = function (key, value) {\n+  exports.HashTable.prototype.put = function (key, data) {\n     var hashCode = this.hashCode(key);\n-    this.elements[hashCode] = value;\n+    var newNode = new Node(key, data);\n+\n+    if (this.elements[hashCode] === null) {\n+      this.elements[hashCode] = newNode;\n+    } else {\n+      var first = this.elements[hashCode];\n+\n+      while (first.next !== null) {\n+        first = first.next;\n+      }\n+\n+      first.next = newNode;\n+      newNode.prev = first;\n+    }\n   };\n \n   exports.HashTable.prototype.get = function (key) {\n     var hashCode = this.hashCode(key);\n-    return this.elements[hashCode];\n+\n+    if (this.elements[hashCode] === null) {\n+      return null;\n+    } else if (this.elements[hashCode].next === null) {\n+      return this.elements[hashCode];\n+    } else {\n+      var first = this.elements[hashCode];\n+\n+      while (first.key !== key) {\n+        first = first.next;\n+      }\n+\n+      return first;\n+    }\n   };\n \n   exports.HashTable.prototype.remove = function (key) {\n     var hashCode = this.hashCode(key);\n-    this.elements.splice(hashCode, 1);\n+\n+    if (this.elements[hashCode] === null) {\n+      return false;\n+    } else if (this.elements[hashCode].next === null) {\n+      this.elements.splice(hashCode, 1);","path":"src/data-structures/hash-table.js","position":83,"original_position":83,"commit_id":"d362b2761b2d14d5f7e85db6c807c17c7d5c3109","original_commit_id":"d362b2761b2d14d5f7e85db6c807c17c7d5c3109","user":{"login":"mgechev","id":455023,"avatar_url":"https://avatars.githubusercontent.com/u/455023?v=3","gravatar_id":"","url":"https://api.github.com/users/mgechev","html_url":"https://github.com/mgechev","followers_url":"https://api.github.com/users/mgechev/followers","following_url":"https://api.github.com/users/mgechev/following{/other_user}","gists_url":"https://api.github.com/users/mgechev/gists{/gist_id}","starred_url":"https://api.github.com/users/mgechev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgechev/subscriptions","organizations_url":"https://api.github.com/users/mgechev/orgs","repos_url":"https://api.github.com/users/mgechev/repos","events_url":"https://api.github.com/users/mgechev/events{/privacy}","received_events_url":"https://api.github.com/users/mgechev/received_events","type":"User","site_admin":false},"body":"Using `splice(hashCode, 1)` will remove the key from the array.\r\nThis means that if we have:\r\n`[{ key: \"foo\", value: \"baz\" }, { key: \"bar\", value: \"foobar\" }]`, `hashCode` has returned `0` for key `foo` and `1` for key `bar`. If you want to remove `foo`, according to the current implementation you'll use: `splice(0, 1)`, this will change the `elements` array to:\r\n`[{ key: \"bar\", value: \"foobar\" }]`. Next time you want to access the element with key `bar` and you invoke `hashCode(bar)`, it will return `1`, but since your array looks like `[{ key: \"bar\", value: \"foobar\" }]`, you'll try to access the index `1`, which value will be `undefined`.","created_at":"2015-05-24T10:59:58Z","updated_at":"2015-05-24T10:59:58Z","html_url":"https://github.com/mgechev/javascript-algorithms/pull/68#discussion_r30951769","pull_request_url":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls/68","_links":{"self":{"href":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls/comments/30951769"},"html":{"href":"https://github.com/mgechev/javascript-algorithms/pull/68#discussion_r30951769"},"pull_request":{"href":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls/68"}}},"pull_request":{"url":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls/68","id":36091950,"html_url":"https://github.com/mgechev/javascript-algorithms/pull/68","diff_url":"https://github.com/mgechev/javascript-algorithms/pull/68.diff","patch_url":"https://github.com/mgechev/javascript-algorithms/pull/68.patch","issue_url":"https://api.github.com/repos/mgechev/javascript-algorithms/issues/68","number":68,"state":"open","locked":false,"title":"Handle collision in the HashMap - Fixes #66","user":{"login":"FilipeFalcaoBatista","id":9125631,"avatar_url":"https://avatars.githubusercontent.com/u/9125631?v=3","gravatar_id":"","url":"https://api.github.com/users/FilipeFalcaoBatista","html_url":"https://github.com/FilipeFalcaoBatista","followers_url":"https://api.github.com/users/FilipeFalcaoBatista/followers","following_url":"https://api.github.com/users/FilipeFalcaoBatista/following{/other_user}","gists_url":"https://api.github.com/users/FilipeFalcaoBatista/gists{/gist_id}","starred_url":"https://api.github.com/users/FilipeFalcaoBatista/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FilipeFalcaoBatista/subscriptions","organizations_url":"https://api.github.com/users/FilipeFalcaoBatista/orgs","repos_url":"https://api.github.com/users/FilipeFalcaoBatista/repos","events_url":"https://api.github.com/users/FilipeFalcaoBatista/events{/privacy}","received_events_url":"https://api.github.com/users/FilipeFalcaoBatista/received_events","type":"User","site_admin":false},"body":"Handle collision in the HashMap with a Linked List","created_at":"2015-05-23T18:59:03Z","updated_at":"2015-05-24T10:59:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls/68/commits","review_comments_url":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls/68/comments","review_comment_url":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mgechev/javascript-algorithms/issues/68/comments","statuses_url":"https://api.github.com/repos/mgechev/javascript-algorithms/statuses/d362b2761b2d14d5f7e85db6c807c17c7d5c3109","head":{"label":"FilipeFalcaoBatista:hash-table","ref":"hash-table","sha":"d362b2761b2d14d5f7e85db6c807c17c7d5c3109","user":{"login":"FilipeFalcaoBatista","id":9125631,"avatar_url":"https://avatars.githubusercontent.com/u/9125631?v=3","gravatar_id":"","url":"https://api.github.com/users/FilipeFalcaoBatista","html_url":"https://github.com/FilipeFalcaoBatista","followers_url":"https://api.github.com/users/FilipeFalcaoBatista/followers","following_url":"https://api.github.com/users/FilipeFalcaoBatista/following{/other_user}","gists_url":"https://api.github.com/users/FilipeFalcaoBatista/gists{/gist_id}","starred_url":"https://api.github.com/users/FilipeFalcaoBatista/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FilipeFalcaoBatista/subscriptions","organizations_url":"https://api.github.com/users/FilipeFalcaoBatista/orgs","repos_url":"https://api.github.com/users/FilipeFalcaoBatista/repos","events_url":"https://api.github.com/users/FilipeFalcaoBatista/events{/privacy}","received_events_url":"https://api.github.com/users/FilipeFalcaoBatista/received_events","type":"User","site_admin":false},"repo":{"id":32365653,"name":"javascript-algorithms","full_name":"FilipeFalcaoBatista/javascript-algorithms","owner":{"login":"FilipeFalcaoBatista","id":9125631,"avatar_url":"https://avatars.githubusercontent.com/u/9125631?v=3","gravatar_id":"","url":"https://api.github.com/users/FilipeFalcaoBatista","html_url":"https://github.com/FilipeFalcaoBatista","followers_url":"https://api.github.com/users/FilipeFalcaoBatista/followers","following_url":"https://api.github.com/users/FilipeFalcaoBatista/following{/other_user}","gists_url":"https://api.github.com/users/FilipeFalcaoBatista/gists{/gist_id}","starred_url":"https://api.github.com/users/FilipeFalcaoBatista/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FilipeFalcaoBatista/subscriptions","organizations_url":"https://api.github.com/users/FilipeFalcaoBatista/orgs","repos_url":"https://api.github.com/users/FilipeFalcaoBatista/repos","events_url":"https://api.github.com/users/FilipeFalcaoBatista/events{/privacy}","received_events_url":"https://api.github.com/users/FilipeFalcaoBatista/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/FilipeFalcaoBatista/javascript-algorithms","description":"JavaScript implementation of different computer science algorithms.","fork":true,"url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms","forks_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/forks","keys_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/teams","hooks_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/hooks","issue_events_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/issues/events{/number}","events_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/events","assignees_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/assignees{/user}","branches_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/branches{/branch}","tags_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/tags","blobs_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/git/refs{/sha}","trees_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/statuses/{sha}","languages_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/languages","stargazers_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/stargazers","contributors_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/contributors","subscribers_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/subscribers","subscription_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/subscription","commits_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/commits{/sha}","git_commits_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/git/commits{/sha}","comments_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/comments{/number}","issue_comment_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/issues/comments{/number}","contents_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/contents/{+path}","compare_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/merges","archive_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/downloads","issues_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/issues{/number}","pulls_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/pulls{/number}","milestones_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/milestones{/number}","notifications_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/labels{/name}","releases_url":"https://api.github.com/repos/FilipeFalcaoBatista/javascript-algorithms/releases{/id}","created_at":"2015-03-17T02:10:10Z","updated_at":"2015-03-17T02:10:11Z","pushed_at":"2015-05-23T18:53:53Z","git_url":"git://github.com/FilipeFalcaoBatista/javascript-algorithms.git","ssh_url":"git@github.com:FilipeFalcaoBatista/javascript-algorithms.git","clone_url":"https://github.com/FilipeFalcaoBatista/javascript-algorithms.git","svn_url":"https://github.com/FilipeFalcaoBatista/javascript-algorithms","homepage":"https://mgechev.github.io/javascript-algorithms/","size":2505,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mgechev:master","ref":"master","sha":"00d997c06615aecdd4e0a6094166eee0b21dc157","user":{"login":"mgechev","id":455023,"avatar_url":"https://avatars.githubusercontent.com/u/455023?v=3","gravatar_id":"","url":"https://api.github.com/users/mgechev","html_url":"https://github.com/mgechev","followers_url":"https://api.github.com/users/mgechev/followers","following_url":"https://api.github.com/users/mgechev/following{/other_user}","gists_url":"https://api.github.com/users/mgechev/gists{/gist_id}","starred_url":"https://api.github.com/users/mgechev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgechev/subscriptions","organizations_url":"https://api.github.com/users/mgechev/orgs","repos_url":"https://api.github.com/users/mgechev/repos","events_url":"https://api.github.com/users/mgechev/events{/privacy}","received_events_url":"https://api.github.com/users/mgechev/received_events","type":"User","site_admin":false},"repo":{"id":6750158,"name":"javascript-algorithms","full_name":"mgechev/javascript-algorithms","owner":{"login":"mgechev","id":455023,"avatar_url":"https://avatars.githubusercontent.com/u/455023?v=3","gravatar_id":"","url":"https://api.github.com/users/mgechev","html_url":"https://github.com/mgechev","followers_url":"https://api.github.com/users/mgechev/followers","following_url":"https://api.github.com/users/mgechev/following{/other_user}","gists_url":"https://api.github.com/users/mgechev/gists{/gist_id}","starred_url":"https://api.github.com/users/mgechev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgechev/subscriptions","organizations_url":"https://api.github.com/users/mgechev/orgs","repos_url":"https://api.github.com/users/mgechev/repos","events_url":"https://api.github.com/users/mgechev/events{/privacy}","received_events_url":"https://api.github.com/users/mgechev/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mgechev/javascript-algorithms","description":"JavaScript implementation of different computer science algorithms.","fork":false,"url":"https://api.github.com/repos/mgechev/javascript-algorithms","forks_url":"https://api.github.com/repos/mgechev/javascript-algorithms/forks","keys_url":"https://api.github.com/repos/mgechev/javascript-algorithms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mgechev/javascript-algorithms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mgechev/javascript-algorithms/teams","hooks_url":"https://api.github.com/repos/mgechev/javascript-algorithms/hooks","issue_events_url":"https://api.github.com/repos/mgechev/javascript-algorithms/issues/events{/number}","events_url":"https://api.github.com/repos/mgechev/javascript-algorithms/events","assignees_url":"https://api.github.com/repos/mgechev/javascript-algorithms/assignees{/user}","branches_url":"https://api.github.com/repos/mgechev/javascript-algorithms/branches{/branch}","tags_url":"https://api.github.com/repos/mgechev/javascript-algorithms/tags","blobs_url":"https://api.github.com/repos/mgechev/javascript-algorithms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mgechev/javascript-algorithms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mgechev/javascript-algorithms/git/refs{/sha}","trees_url":"https://api.github.com/repos/mgechev/javascript-algorithms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mgechev/javascript-algorithms/statuses/{sha}","languages_url":"https://api.github.com/repos/mgechev/javascript-algorithms/languages","stargazers_url":"https://api.github.com/repos/mgechev/javascript-algorithms/stargazers","contributors_url":"https://api.github.com/repos/mgechev/javascript-algorithms/contributors","subscribers_url":"https://api.github.com/repos/mgechev/javascript-algorithms/subscribers","subscription_url":"https://api.github.com/repos/mgechev/javascript-algorithms/subscription","commits_url":"https://api.github.com/repos/mgechev/javascript-algorithms/commits{/sha}","git_commits_url":"https://api.github.com/repos/mgechev/javascript-algorithms/git/commits{/sha}","comments_url":"https://api.github.com/repos/mgechev/javascript-algorithms/comments{/number}","issue_comment_url":"https://api.github.com/repos/mgechev/javascript-algorithms/issues/comments{/number}","contents_url":"https://api.github.com/repos/mgechev/javascript-algorithms/contents/{+path}","compare_url":"https://api.github.com/repos/mgechev/javascript-algorithms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mgechev/javascript-algorithms/merges","archive_url":"https://api.github.com/repos/mgechev/javascript-algorithms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mgechev/javascript-algorithms/downloads","issues_url":"https://api.github.com/repos/mgechev/javascript-algorithms/issues{/number}","pulls_url":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls{/number}","milestones_url":"https://api.github.com/repos/mgechev/javascript-algorithms/milestones{/number}","notifications_url":"https://api.github.com/repos/mgechev/javascript-algorithms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mgechev/javascript-algorithms/labels{/name}","releases_url":"https://api.github.com/repos/mgechev/javascript-algorithms/releases{/id}","created_at":"2012-11-18T19:11:57Z","updated_at":"2015-05-22T07:29:37Z","pushed_at":"2015-05-23T18:59:03Z","git_url":"git://github.com/mgechev/javascript-algorithms.git","ssh_url":"git@github.com:mgechev/javascript-algorithms.git","clone_url":"https://github.com/mgechev/javascript-algorithms.git","svn_url":"https://github.com/mgechev/javascript-algorithms","homepage":"https://mgechev.github.io/javascript-algorithms/","size":4528,"stargazers_count":1019,"watchers_count":1019,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":190,"mirror_url":null,"open_issues_count":6,"forks":190,"open_issues":6,"watchers":1019,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls/68"},"html":{"href":"https://github.com/mgechev/javascript-algorithms/pull/68"},"issue":{"href":"https://api.github.com/repos/mgechev/javascript-algorithms/issues/68"},"comments":{"href":"https://api.github.com/repos/mgechev/javascript-algorithms/issues/68/comments"},"review_comments":{"href":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls/68/comments"},"review_comment":{"href":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mgechev/javascript-algorithms/pulls/68/commits"},"statuses":{"href":"https://api.github.com/repos/mgechev/javascript-algorithms/statuses/d362b2761b2d14d5f7e85db6c807c17c7d5c3109"}}}}