{"action":"created","comment":{"url":"https://api.github.com/repos/bluss/fixedbitset/pulls/comments/84450522","pull_request_review_id":5228783,"id":84450522,"diff_hunk":"@@ -141,6 +144,28 @@ impl FixedBitSet\n         }\n     }\n \n+    pub fn count_ones<T: IndexRange>(&self, range: T) -> usize\n+    {\n+        let start = range.start().unwrap_or(0);\n+        let end = range.end().unwrap_or(self.length - 1);\n+        // range makes sure that range.start <= range.end\n+        assert!(end < self.length);\n+        let (first_block, first_rem) = div_rem(start, BITS);\n+        let (last_block, last_rem) = div_rem(end, BITS);\n+        let mut sum = 0usize;\n+        // we can't skip first_block in case first_block == last_block\n+        for block in &self.data[first_block..last_block] {\n+            sum += block.count_ones() as usize;\n+        }\n+        // calculate masks; deals with overflowing shr problem when x == 0\n+        let mask = |x| if x != 0 { Block::max_value() >> (BITS - x) } else { 0 };\n+        let mask_first_block: Block = mask(first_rem);\n+        let mask_last_block: Block = mask(last_rem);\n+        sum += (self.data[last_block] & mask_last_block).count_ones() as usize;\n+        sum -= (self.data[first_block] & mask_first_block).count_ones() as usize;","path":"src/lib.rs","position":33,"original_position":33,"commit_id":"b3f1c48be9700b719203eafee980f8f67ddfbdcc","original_commit_id":"b3f1c48be9700b719203eafee980f8f67ddfbdcc","user":{"login":"bluss","id":3209739,"avatar_url":"https://avatars.githubusercontent.com/u/3209739?v=3","gravatar_id":"","url":"https://api.github.com/users/bluss","html_url":"https://github.com/bluss","followers_url":"https://api.github.com/users/bluss/followers","following_url":"https://api.github.com/users/bluss/following{/other_user}","gists_url":"https://api.github.com/users/bluss/gists{/gist_id}","starred_url":"https://api.github.com/users/bluss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluss/subscriptions","organizations_url":"https://api.github.com/users/bluss/orgs","repos_url":"https://api.github.com/users/bluss/repos","events_url":"https://api.github.com/users/bluss/events{/privacy}","received_events_url":"https://api.github.com/users/bluss/received_events","type":"User","site_admin":false},"body":"Thanks for the explanation","created_at":"2016-10-21T09:51:50Z","updated_at":"2016-10-21T09:51:50Z","html_url":"https://github.com/bluss/fixedbitset/pull/5#discussion_r84450522","pull_request_url":"https://api.github.com/repos/bluss/fixedbitset/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/bluss/fixedbitset/pulls/comments/84450522"},"html":{"href":"https://github.com/bluss/fixedbitset/pull/5#discussion_r84450522"},"pull_request":{"href":"https://api.github.com/repos/bluss/fixedbitset/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/bluss/fixedbitset/pulls/5","id":89097061,"html_url":"https://github.com/bluss/fixedbitset/pull/5","diff_url":"https://github.com/bluss/fixedbitset/pull/5.diff","patch_url":"https://github.com/bluss/fixedbitset/pull/5.patch","issue_url":"https://api.github.com/repos/bluss/fixedbitset/issues/5","number":5,"state":"open","locked":false,"title":"added count_ones function","user":{"login":"fuine","id":15677456,"avatar_url":"https://avatars.githubusercontent.com/u/15677456?v=3","gravatar_id":"","url":"https://api.github.com/users/fuine","html_url":"https://github.com/fuine","followers_url":"https://api.github.com/users/fuine/followers","following_url":"https://api.github.com/users/fuine/following{/other_user}","gists_url":"https://api.github.com/users/fuine/gists{/gist_id}","starred_url":"https://api.github.com/users/fuine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fuine/subscriptions","organizations_url":"https://api.github.com/users/fuine/orgs","repos_url":"https://api.github.com/users/fuine/repos","events_url":"https://api.github.com/users/fuine/events{/privacy}","received_events_url":"https://api.github.com/users/fuine/received_events","type":"User","site_admin":false},"body":"This solves #4. Please note that proposed implementation can most probably be further optimized (for example if the remainder is 0 then we can completely skip `mask` creation and `sum` modification). Please let me know what do you think about this @bluss.","created_at":"2016-10-12T21:25:46Z","updated_at":"2016-10-21T09:51:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"47b9cdf987be4ca1e4011a8212056bc3f858c5f3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/bluss/fixedbitset/pulls/5/commits","review_comments_url":"https://api.github.com/repos/bluss/fixedbitset/pulls/5/comments","review_comment_url":"https://api.github.com/repos/bluss/fixedbitset/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bluss/fixedbitset/issues/5/comments","statuses_url":"https://api.github.com/repos/bluss/fixedbitset/statuses/b3f1c48be9700b719203eafee980f8f67ddfbdcc","head":{"label":"fuine:count_ones","ref":"count_ones","sha":"b3f1c48be9700b719203eafee980f8f67ddfbdcc","user":{"login":"fuine","id":15677456,"avatar_url":"https://avatars.githubusercontent.com/u/15677456?v=3","gravatar_id":"","url":"https://api.github.com/users/fuine","html_url":"https://github.com/fuine","followers_url":"https://api.github.com/users/fuine/followers","following_url":"https://api.github.com/users/fuine/following{/other_user}","gists_url":"https://api.github.com/users/fuine/gists{/gist_id}","starred_url":"https://api.github.com/users/fuine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fuine/subscriptions","organizations_url":"https://api.github.com/users/fuine/orgs","repos_url":"https://api.github.com/users/fuine/repos","events_url":"https://api.github.com/users/fuine/events{/privacy}","received_events_url":"https://api.github.com/users/fuine/received_events","type":"User","site_admin":false},"repo":{"id":68289427,"name":"fixedbitset","full_name":"fuine/fixedbitset","owner":{"login":"fuine","id":15677456,"avatar_url":"https://avatars.githubusercontent.com/u/15677456?v=3","gravatar_id":"","url":"https://api.github.com/users/fuine","html_url":"https://github.com/fuine","followers_url":"https://api.github.com/users/fuine/followers","following_url":"https://api.github.com/users/fuine/following{/other_user}","gists_url":"https://api.github.com/users/fuine/gists{/gist_id}","starred_url":"https://api.github.com/users/fuine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fuine/subscriptions","organizations_url":"https://api.github.com/users/fuine/orgs","repos_url":"https://api.github.com/users/fuine/repos","events_url":"https://api.github.com/users/fuine/events{/privacy}","received_events_url":"https://api.github.com/users/fuine/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fuine/fixedbitset","description":"Rust simple BitSet type","fork":true,"url":"https://api.github.com/repos/fuine/fixedbitset","forks_url":"https://api.github.com/repos/fuine/fixedbitset/forks","keys_url":"https://api.github.com/repos/fuine/fixedbitset/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fuine/fixedbitset/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fuine/fixedbitset/teams","hooks_url":"https://api.github.com/repos/fuine/fixedbitset/hooks","issue_events_url":"https://api.github.com/repos/fuine/fixedbitset/issues/events{/number}","events_url":"https://api.github.com/repos/fuine/fixedbitset/events","assignees_url":"https://api.github.com/repos/fuine/fixedbitset/assignees{/user}","branches_url":"https://api.github.com/repos/fuine/fixedbitset/branches{/branch}","tags_url":"https://api.github.com/repos/fuine/fixedbitset/tags","blobs_url":"https://api.github.com/repos/fuine/fixedbitset/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fuine/fixedbitset/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fuine/fixedbitset/git/refs{/sha}","trees_url":"https://api.github.com/repos/fuine/fixedbitset/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fuine/fixedbitset/statuses/{sha}","languages_url":"https://api.github.com/repos/fuine/fixedbitset/languages","stargazers_url":"https://api.github.com/repos/fuine/fixedbitset/stargazers","contributors_url":"https://api.github.com/repos/fuine/fixedbitset/contributors","subscribers_url":"https://api.github.com/repos/fuine/fixedbitset/subscribers","subscription_url":"https://api.github.com/repos/fuine/fixedbitset/subscription","commits_url":"https://api.github.com/repos/fuine/fixedbitset/commits{/sha}","git_commits_url":"https://api.github.com/repos/fuine/fixedbitset/git/commits{/sha}","comments_url":"https://api.github.com/repos/fuine/fixedbitset/comments{/number}","issue_comment_url":"https://api.github.com/repos/fuine/fixedbitset/issues/comments{/number}","contents_url":"https://api.github.com/repos/fuine/fixedbitset/contents/{+path}","compare_url":"https://api.github.com/repos/fuine/fixedbitset/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fuine/fixedbitset/merges","archive_url":"https://api.github.com/repos/fuine/fixedbitset/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fuine/fixedbitset/downloads","issues_url":"https://api.github.com/repos/fuine/fixedbitset/issues{/number}","pulls_url":"https://api.github.com/repos/fuine/fixedbitset/pulls{/number}","milestones_url":"https://api.github.com/repos/fuine/fixedbitset/milestones{/number}","notifications_url":"https://api.github.com/repos/fuine/fixedbitset/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fuine/fixedbitset/labels{/name}","releases_url":"https://api.github.com/repos/fuine/fixedbitset/releases{/id}","deployments_url":"https://api.github.com/repos/fuine/fixedbitset/deployments","created_at":"2016-09-15T11:48:48Z","updated_at":"2016-09-15T11:48:49Z","pushed_at":"2016-10-12T21:22:22Z","git_url":"git://github.com/fuine/fixedbitset.git","ssh_url":"git@github.com:fuine/fixedbitset.git","clone_url":"https://github.com/fuine/fixedbitset.git","svn_url":"https://github.com/fuine/fixedbitset","homepage":"https://bluss.github.io/petgraph/doc/fixedbitset/","size":16,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"bluss:master","ref":"master","sha":"5e175acf56cadb87891f6ffa9862a64c5d1be371","user":{"login":"bluss","id":3209739,"avatar_url":"https://avatars.githubusercontent.com/u/3209739?v=3","gravatar_id":"","url":"https://api.github.com/users/bluss","html_url":"https://github.com/bluss","followers_url":"https://api.github.com/users/bluss/followers","following_url":"https://api.github.com/users/bluss/following{/other_user}","gists_url":"https://api.github.com/users/bluss/gists{/gist_id}","starred_url":"https://api.github.com/users/bluss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluss/subscriptions","organizations_url":"https://api.github.com/users/bluss/orgs","repos_url":"https://api.github.com/users/bluss/repos","events_url":"https://api.github.com/users/bluss/events{/privacy}","received_events_url":"https://api.github.com/users/bluss/received_events","type":"User","site_admin":false},"repo":{"id":33360229,"name":"fixedbitset","full_name":"bluss/fixedbitset","owner":{"login":"bluss","id":3209739,"avatar_url":"https://avatars.githubusercontent.com/u/3209739?v=3","gravatar_id":"","url":"https://api.github.com/users/bluss","html_url":"https://github.com/bluss","followers_url":"https://api.github.com/users/bluss/followers","following_url":"https://api.github.com/users/bluss/following{/other_user}","gists_url":"https://api.github.com/users/bluss/gists{/gist_id}","starred_url":"https://api.github.com/users/bluss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluss/subscriptions","organizations_url":"https://api.github.com/users/bluss/orgs","repos_url":"https://api.github.com/users/bluss/repos","events_url":"https://api.github.com/users/bluss/events{/privacy}","received_events_url":"https://api.github.com/users/bluss/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bluss/fixedbitset","description":"A simple bitset container for Rust","fork":false,"url":"https://api.github.com/repos/bluss/fixedbitset","forks_url":"https://api.github.com/repos/bluss/fixedbitset/forks","keys_url":"https://api.github.com/repos/bluss/fixedbitset/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bluss/fixedbitset/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bluss/fixedbitset/teams","hooks_url":"https://api.github.com/repos/bluss/fixedbitset/hooks","issue_events_url":"https://api.github.com/repos/bluss/fixedbitset/issues/events{/number}","events_url":"https://api.github.com/repos/bluss/fixedbitset/events","assignees_url":"https://api.github.com/repos/bluss/fixedbitset/assignees{/user}","branches_url":"https://api.github.com/repos/bluss/fixedbitset/branches{/branch}","tags_url":"https://api.github.com/repos/bluss/fixedbitset/tags","blobs_url":"https://api.github.com/repos/bluss/fixedbitset/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bluss/fixedbitset/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bluss/fixedbitset/git/refs{/sha}","trees_url":"https://api.github.com/repos/bluss/fixedbitset/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bluss/fixedbitset/statuses/{sha}","languages_url":"https://api.github.com/repos/bluss/fixedbitset/languages","stargazers_url":"https://api.github.com/repos/bluss/fixedbitset/stargazers","contributors_url":"https://api.github.com/repos/bluss/fixedbitset/contributors","subscribers_url":"https://api.github.com/repos/bluss/fixedbitset/subscribers","subscription_url":"https://api.github.com/repos/bluss/fixedbitset/subscription","commits_url":"https://api.github.com/repos/bluss/fixedbitset/commits{/sha}","git_commits_url":"https://api.github.com/repos/bluss/fixedbitset/git/commits{/sha}","comments_url":"https://api.github.com/repos/bluss/fixedbitset/comments{/number}","issue_comment_url":"https://api.github.com/repos/bluss/fixedbitset/issues/comments{/number}","contents_url":"https://api.github.com/repos/bluss/fixedbitset/contents/{+path}","compare_url":"https://api.github.com/repos/bluss/fixedbitset/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bluss/fixedbitset/merges","archive_url":"https://api.github.com/repos/bluss/fixedbitset/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bluss/fixedbitset/downloads","issues_url":"https://api.github.com/repos/bluss/fixedbitset/issues{/number}","pulls_url":"https://api.github.com/repos/bluss/fixedbitset/pulls{/number}","milestones_url":"https://api.github.com/repos/bluss/fixedbitset/milestones{/number}","notifications_url":"https://api.github.com/repos/bluss/fixedbitset/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bluss/fixedbitset/labels{/name}","releases_url":"https://api.github.com/repos/bluss/fixedbitset/releases{/id}","deployments_url":"https://api.github.com/repos/bluss/fixedbitset/deployments","created_at":"2015-04-03T11:23:14Z","updated_at":"2016-10-05T09:33:09Z","pushed_at":"2016-10-12T21:25:47Z","git_url":"git://github.com/bluss/fixedbitset.git","ssh_url":"git@github.com:bluss/fixedbitset.git","clone_url":"https://github.com/bluss/fixedbitset.git","svn_url":"https://github.com/bluss/fixedbitset","homepage":"https://docs.rs/fixedbitset/","size":15,"stargazers_count":1,"watchers_count":1,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bluss/fixedbitset/pulls/5"},"html":{"href":"https://github.com/bluss/fixedbitset/pull/5"},"issue":{"href":"https://api.github.com/repos/bluss/fixedbitset/issues/5"},"comments":{"href":"https://api.github.com/repos/bluss/fixedbitset/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/bluss/fixedbitset/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/bluss/fixedbitset/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bluss/fixedbitset/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/bluss/fixedbitset/statuses/b3f1c48be9700b719203eafee980f8f67ddfbdcc"}}}}
{"actor":{"display_login":"bluss"}}