{"action":"created","comment":{"url":"https://api.github.com/repos/SignHash/signhash-contracts/pulls/comments/148928091","pull_request_review_id":74252573,"id":148928091,"diff_hunk":"@@ -2,40 +2,139 @@ pragma solidity ^0.4.18;\n \n \n library AddressSet {\n+\n+    //--- Definitions\n+\n+    struct Link {\n+        address previous;\n+        address next;\n+    }\n+\n     struct Data {\n-        address[] list;\n-        mapping (address => uint256) index; // 1..n, 0 means it does not exists\n+        address head;\n+        address tail;\n+        uint256 count;\n+        mapping (address => Link) links;\n     }\n \n-    function add(Data storage self, address element) public {\n-        if (self.index[element] == 0) {\n-            self.list.push(element);\n-            self.index[element] = self.list.length;\n+    //--- Public mutable functions\n+\n+    function add(\n+        Data storage self,\n+        address element\n+    )\n+        internal\n+        returns (bool added)\n+    {\n+        require(element != address(0));\n+\n+        if (self.count == 0) {\n+            self.head = element;\n+            added = true;\n+        } else if (!contains(self, element)) {\n+            self.links[self.tail].next = element;\n+            self.links[element].previous = self.tail;\n+            added = true;\n+        }\n+\n+        if (added) {\n+            self.tail = element;\n+            safeIncrement(self);\n         }\n     }\n \n-    function remove(Data storage self, address element) public {\n-        // preserves initial order of elements, can be optimized if not required\n+    function remove(\n+        Data storage self,\n+        address element\n+    )\n+        internal\n+        returns (bool removed)\n+    {\n+        require(element != address(0));\n+\n+        Link storage link = self.links[element];\n+","path":"contracts/AddressSet.sol","position":63,"original_position":63,"commit_id":"cce13b7d1d17a9642e3d171dfea2b7261066c7fa","original_commit_id":"cce13b7d1d17a9642e3d171dfea2b7261066c7fa","user":{"login":"biern","id":41862,"avatar_url":"https://avatars2.githubusercontent.com/u/41862?v=4","gravatar_id":"","url":"https://api.github.com/users/biern","html_url":"https://github.com/biern","followers_url":"https://api.github.com/users/biern/followers","following_url":"https://api.github.com/users/biern/following{/other_user}","gists_url":"https://api.github.com/users/biern/gists{/gist_id}","starred_url":"https://api.github.com/users/biern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biern/subscriptions","organizations_url":"https://api.github.com/users/biern/orgs","repos_url":"https://api.github.com/users/biern/repos","events_url":"https://api.github.com/users/biern/events{/privacy}","received_events_url":"https://api.github.com/users/biern/received_events","type":"User","site_admin":false},"body":"I think this code can be made simpler by:\r\n- checking if element exists in the beginning and returning false if not.\r\n- Then switching the order of `head` / `tail` checking if's, like this and removing the `else if` condition:\r\n```\r\n        if (element == self.head) {\r\n            self.head = link.next;\r\n        } else {\r\n            self.links[link.previous].next = link.next;\r\n        }  \r\n```\r\n- removing the `if (removed) part`, it's safeguarded in the beginning\r\n- and then always explicitly returning true in the end.","created_at":"2017-11-04T11:16:51Z","updated_at":"2017-11-04T11:33:20Z","html_url":"https://github.com/SignHash/signhash-contracts/pull/18#discussion_r148928091","pull_request_url":"https://api.github.com/repos/SignHash/signhash-contracts/pulls/18","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/SignHash/signhash-contracts/pulls/comments/148928091"},"html":{"href":"https://github.com/SignHash/signhash-contracts/pull/18#discussion_r148928091"},"pull_request":{"href":"https://api.github.com/repos/SignHash/signhash-contracts/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/SignHash/signhash-contracts/pulls/18","id":150424853,"html_url":"https://github.com/SignHash/signhash-contracts/pull/18","diff_url":"https://github.com/SignHash/signhash-contracts/pull/18.diff","patch_url":"https://github.com/SignHash/signhash-contracts/pull/18.patch","issue_url":"https://api.github.com/repos/SignHash/signhash-contracts/issues/18","number":18,"state":"open","locked":false,"title":"Make all signers operations constant time","user":{"login":"jstefanski","id":3219720,"avatar_url":"https://avatars2.githubusercontent.com/u/3219720?v=4","gravatar_id":"","url":"https://api.github.com/users/jstefanski","html_url":"https://github.com/jstefanski","followers_url":"https://api.github.com/users/jstefanski/followers","following_url":"https://api.github.com/users/jstefanski/following{/other_user}","gists_url":"https://api.github.com/users/jstefanski/gists{/gist_id}","starred_url":"https://api.github.com/users/jstefanski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jstefanski/subscriptions","organizations_url":"https://api.github.com/users/jstefanski/orgs","repos_url":"https://api.github.com/users/jstefanski/repos","events_url":"https://api.github.com/users/jstefanski/events{/privacy}","received_events_url":"https://api.github.com/users/jstefanski/received_events","type":"User","site_admin":false},"body":"Changed `AddressSet` implementation. Previously, an array was used, and removing elements had linear complexity (preserving chronological order is crucial).\r\nCurrently, I implemented signers list as a variation of a double linked list with an index. \r\nThis way, both adding and removing signers is constant time.\r\nThere is more hassle to iterate, but it is done in read-only calls.\r\n\r\nI also improved tests coverage, refactored a bit and added `maxCount` parameter to `getSigners()` method. I believe we should always restrict the maximum number of elements to prevent spam slowing down the application.\r\n\r\nI plan to improve on-chain interoperability of the contract and paging of signers, but I'll make a separate PR for these.\r\n\r\nCloses #17 ","created_at":"2017-11-02T23:02:39Z","updated_at":"2017-11-04T11:33:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f4c797be61b9e79b7fa6d13314eb7313f76a52dc","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/SignHash/signhash-contracts/pulls/18/commits","review_comments_url":"https://api.github.com/repos/SignHash/signhash-contracts/pulls/18/comments","review_comment_url":"https://api.github.com/repos/SignHash/signhash-contracts/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SignHash/signhash-contracts/issues/18/comments","statuses_url":"https://api.github.com/repos/SignHash/signhash-contracts/statuses/cce13b7d1d17a9642e3d171dfea2b7261066c7fa","head":{"label":"jstefanski:feature/improve-revoke","ref":"feature/improve-revoke","sha":"cce13b7d1d17a9642e3d171dfea2b7261066c7fa","user":{"login":"jstefanski","id":3219720,"avatar_url":"https://avatars2.githubusercontent.com/u/3219720?v=4","gravatar_id":"","url":"https://api.github.com/users/jstefanski","html_url":"https://github.com/jstefanski","followers_url":"https://api.github.com/users/jstefanski/followers","following_url":"https://api.github.com/users/jstefanski/following{/other_user}","gists_url":"https://api.github.com/users/jstefanski/gists{/gist_id}","starred_url":"https://api.github.com/users/jstefanski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jstefanski/subscriptions","organizations_url":"https://api.github.com/users/jstefanski/orgs","repos_url":"https://api.github.com/users/jstefanski/repos","events_url":"https://api.github.com/users/jstefanski/events{/privacy}","received_events_url":"https://api.github.com/users/jstefanski/received_events","type":"User","site_admin":false},"repo":{"id":105429851,"name":"signhash-contracts","full_name":"jstefanski/signhash-contracts","owner":{"login":"jstefanski","id":3219720,"avatar_url":"https://avatars2.githubusercontent.com/u/3219720?v=4","gravatar_id":"","url":"https://api.github.com/users/jstefanski","html_url":"https://github.com/jstefanski","followers_url":"https://api.github.com/users/jstefanski/followers","following_url":"https://api.github.com/users/jstefanski/following{/other_user}","gists_url":"https://api.github.com/users/jstefanski/gists{/gist_id}","starred_url":"https://api.github.com/users/jstefanski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jstefanski/subscriptions","organizations_url":"https://api.github.com/users/jstefanski/orgs","repos_url":"https://api.github.com/users/jstefanski/repos","events_url":"https://api.github.com/users/jstefanski/events{/privacy}","received_events_url":"https://api.github.com/users/jstefanski/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jstefanski/signhash-contracts","description":"SignHash smart contracts","fork":true,"url":"https://api.github.com/repos/jstefanski/signhash-contracts","forks_url":"https://api.github.com/repos/jstefanski/signhash-contracts/forks","keys_url":"https://api.github.com/repos/jstefanski/signhash-contracts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jstefanski/signhash-contracts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jstefanski/signhash-contracts/teams","hooks_url":"https://api.github.com/repos/jstefanski/signhash-contracts/hooks","issue_events_url":"https://api.github.com/repos/jstefanski/signhash-contracts/issues/events{/number}","events_url":"https://api.github.com/repos/jstefanski/signhash-contracts/events","assignees_url":"https://api.github.com/repos/jstefanski/signhash-contracts/assignees{/user}","branches_url":"https://api.github.com/repos/jstefanski/signhash-contracts/branches{/branch}","tags_url":"https://api.github.com/repos/jstefanski/signhash-contracts/tags","blobs_url":"https://api.github.com/repos/jstefanski/signhash-contracts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jstefanski/signhash-contracts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jstefanski/signhash-contracts/git/refs{/sha}","trees_url":"https://api.github.com/repos/jstefanski/signhash-contracts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jstefanski/signhash-contracts/statuses/{sha}","languages_url":"https://api.github.com/repos/jstefanski/signhash-contracts/languages","stargazers_url":"https://api.github.com/repos/jstefanski/signhash-contracts/stargazers","contributors_url":"https://api.github.com/repos/jstefanski/signhash-contracts/contributors","subscribers_url":"https://api.github.com/repos/jstefanski/signhash-contracts/subscribers","subscription_url":"https://api.github.com/repos/jstefanski/signhash-contracts/subscription","commits_url":"https://api.github.com/repos/jstefanski/signhash-contracts/commits{/sha}","git_commits_url":"https://api.github.com/repos/jstefanski/signhash-contracts/git/commits{/sha}","comments_url":"https://api.github.com/repos/jstefanski/signhash-contracts/comments{/number}","issue_comment_url":"https://api.github.com/repos/jstefanski/signhash-contracts/issues/comments{/number}","contents_url":"https://api.github.com/repos/jstefanski/signhash-contracts/contents/{+path}","compare_url":"https://api.github.com/repos/jstefanski/signhash-contracts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jstefanski/signhash-contracts/merges","archive_url":"https://api.github.com/repos/jstefanski/signhash-contracts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jstefanski/signhash-contracts/downloads","issues_url":"https://api.github.com/repos/jstefanski/signhash-contracts/issues{/number}","pulls_url":"https://api.github.com/repos/jstefanski/signhash-contracts/pulls{/number}","milestones_url":"https://api.github.com/repos/jstefanski/signhash-contracts/milestones{/number}","notifications_url":"https://api.github.com/repos/jstefanski/signhash-contracts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jstefanski/signhash-contracts/labels{/name}","releases_url":"https://api.github.com/repos/jstefanski/signhash-contracts/releases{/id}","deployments_url":"https://api.github.com/repos/jstefanski/signhash-contracts/deployments","created_at":"2017-10-01T08:48:21Z","updated_at":"2017-10-01T08:48:23Z","pushed_at":"2017-11-02T22:52:41Z","git_url":"git://github.com/jstefanski/signhash-contracts.git","ssh_url":"git@github.com:jstefanski/signhash-contracts.git","clone_url":"https://github.com/jstefanski/signhash-contracts.git","svn_url":"https://github.com/jstefanski/signhash-contracts","homepage":null,"size":120,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"SignHash:master","ref":"master","sha":"d184d6d3ab5b28ffb8830da66618f32625549551","user":{"login":"SignHash","id":31995450,"avatar_url":"https://avatars1.githubusercontent.com/u/31995450?v=4","gravatar_id":"","url":"https://api.github.com/users/SignHash","html_url":"https://github.com/SignHash","followers_url":"https://api.github.com/users/SignHash/followers","following_url":"https://api.github.com/users/SignHash/following{/other_user}","gists_url":"https://api.github.com/users/SignHash/gists{/gist_id}","starred_url":"https://api.github.com/users/SignHash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SignHash/subscriptions","organizations_url":"https://api.github.com/users/SignHash/orgs","repos_url":"https://api.github.com/users/SignHash/repos","events_url":"https://api.github.com/users/SignHash/events{/privacy}","received_events_url":"https://api.github.com/users/SignHash/received_events","type":"Organization","site_admin":false},"repo":{"id":103677642,"name":"signhash-contracts","full_name":"SignHash/signhash-contracts","owner":{"login":"SignHash","id":31995450,"avatar_url":"https://avatars1.githubusercontent.com/u/31995450?v=4","gravatar_id":"","url":"https://api.github.com/users/SignHash","html_url":"https://github.com/SignHash","followers_url":"https://api.github.com/users/SignHash/followers","following_url":"https://api.github.com/users/SignHash/following{/other_user}","gists_url":"https://api.github.com/users/SignHash/gists{/gist_id}","starred_url":"https://api.github.com/users/SignHash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SignHash/subscriptions","organizations_url":"https://api.github.com/users/SignHash/orgs","repos_url":"https://api.github.com/users/SignHash/repos","events_url":"https://api.github.com/users/SignHash/events{/privacy}","received_events_url":"https://api.github.com/users/SignHash/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SignHash/signhash-contracts","description":"SignHash smart contracts","fork":false,"url":"https://api.github.com/repos/SignHash/signhash-contracts","forks_url":"https://api.github.com/repos/SignHash/signhash-contracts/forks","keys_url":"https://api.github.com/repos/SignHash/signhash-contracts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SignHash/signhash-contracts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SignHash/signhash-contracts/teams","hooks_url":"https://api.github.com/repos/SignHash/signhash-contracts/hooks","issue_events_url":"https://api.github.com/repos/SignHash/signhash-contracts/issues/events{/number}","events_url":"https://api.github.com/repos/SignHash/signhash-contracts/events","assignees_url":"https://api.github.com/repos/SignHash/signhash-contracts/assignees{/user}","branches_url":"https://api.github.com/repos/SignHash/signhash-contracts/branches{/branch}","tags_url":"https://api.github.com/repos/SignHash/signhash-contracts/tags","blobs_url":"https://api.github.com/repos/SignHash/signhash-contracts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SignHash/signhash-contracts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SignHash/signhash-contracts/git/refs{/sha}","trees_url":"https://api.github.com/repos/SignHash/signhash-contracts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SignHash/signhash-contracts/statuses/{sha}","languages_url":"https://api.github.com/repos/SignHash/signhash-contracts/languages","stargazers_url":"https://api.github.com/repos/SignHash/signhash-contracts/stargazers","contributors_url":"https://api.github.com/repos/SignHash/signhash-contracts/contributors","subscribers_url":"https://api.github.com/repos/SignHash/signhash-contracts/subscribers","subscription_url":"https://api.github.com/repos/SignHash/signhash-contracts/subscription","commits_url":"https://api.github.com/repos/SignHash/signhash-contracts/commits{/sha}","git_commits_url":"https://api.github.com/repos/SignHash/signhash-contracts/git/commits{/sha}","comments_url":"https://api.github.com/repos/SignHash/signhash-contracts/comments{/number}","issue_comment_url":"https://api.github.com/repos/SignHash/signhash-contracts/issues/comments{/number}","contents_url":"https://api.github.com/repos/SignHash/signhash-contracts/contents/{+path}","compare_url":"https://api.github.com/repos/SignHash/signhash-contracts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SignHash/signhash-contracts/merges","archive_url":"https://api.github.com/repos/SignHash/signhash-contracts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SignHash/signhash-contracts/downloads","issues_url":"https://api.github.com/repos/SignHash/signhash-contracts/issues{/number}","pulls_url":"https://api.github.com/repos/SignHash/signhash-contracts/pulls{/number}","milestones_url":"https://api.github.com/repos/SignHash/signhash-contracts/milestones{/number}","notifications_url":"https://api.github.com/repos/SignHash/signhash-contracts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SignHash/signhash-contracts/labels{/name}","releases_url":"https://api.github.com/repos/SignHash/signhash-contracts/releases{/id}","deployments_url":"https://api.github.com/repos/SignHash/signhash-contracts/deployments","created_at":"2017-09-15T16:20:03Z","updated_at":"2017-10-02T20:41:43Z","pushed_at":"2017-11-02T23:02:58Z","git_url":"git://github.com/SignHash/signhash-contracts.git","ssh_url":"git@github.com:SignHash/signhash-contracts.git","clone_url":"https://github.com/SignHash/signhash-contracts.git","svn_url":"https://github.com/SignHash/signhash-contracts","homepage":null,"size":120,"stargazers_count":1,"watchers_count":1,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":8,"forks":1,"open_issues":8,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SignHash/signhash-contracts/pulls/18"},"html":{"href":"https://github.com/SignHash/signhash-contracts/pull/18"},"issue":{"href":"https://api.github.com/repos/SignHash/signhash-contracts/issues/18"},"comments":{"href":"https://api.github.com/repos/SignHash/signhash-contracts/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/SignHash/signhash-contracts/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/SignHash/signhash-contracts/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SignHash/signhash-contracts/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/SignHash/signhash-contracts/statuses/cce13b7d1d17a9642e3d171dfea2b7261066c7fa"}},"author_association":"OWNER"}}
{"actor":{"display_login":"biern"}}