{"action":"created","comment":{"url":"https://api.github.com/repos/manastech/crystal/pulls/comments/43646234","id":43646234,"diff_hunk":"@@ -1770,4 +1770,12 @@ class Array(T)\n       end\n     end\n   end\n+\n+  def bsearch\n+    idx=(0...self.size).bsearch{|i|yield self[i]}\n+    idx ? self[idx] : nil","path":"src/array.cr","position":7,"original_position":7,"commit_id":"1da57ffaad9a1ce1581edbd56c27d10aebae20f3","original_commit_id":"1da57ffaad9a1ce1581edbd56c27d10aebae20f3","user":{"login":"cielavenir","id":1495368,"avatar_url":"https://avatars.githubusercontent.com/u/1495368?v=3","gravatar_id":"","url":"https://api.github.com/users/cielavenir","html_url":"https://github.com/cielavenir","followers_url":"https://api.github.com/users/cielavenir/followers","following_url":"https://api.github.com/users/cielavenir/following{/other_user}","gists_url":"https://api.github.com/users/cielavenir/gists{/gist_id}","starred_url":"https://api.github.com/users/cielavenir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cielavenir/subscriptions","organizations_url":"https://api.github.com/users/cielavenir/orgs","repos_url":"https://api.github.com/users/cielavenir/repos","events_url":"https://api.github.com/users/cielavenir/events{/privacy}","received_events_url":"https://api.github.com/users/cielavenir/received_events","type":"User","site_admin":false},"body":"Uh, in https://github.com/cielavenir/crystal-bsearch/blob/master/lib/bsearch.cr , Array#bsearch is defined after Range#bsearch. We might need to define Array#bsearch in range.cr...","created_at":"2015-11-02T16:19:10Z","updated_at":"2015-11-02T16:19:10Z","html_url":"https://github.com/manastech/crystal/pull/1859#discussion_r43646234","pull_request_url":"https://api.github.com/repos/manastech/crystal/pulls/1859","_links":{"self":{"href":"https://api.github.com/repos/manastech/crystal/pulls/comments/43646234"},"html":{"href":"https://github.com/manastech/crystal/pull/1859#discussion_r43646234"},"pull_request":{"href":"https://api.github.com/repos/manastech/crystal/pulls/1859"}}},"pull_request":{"url":"https://api.github.com/repos/manastech/crystal/pulls/1859","id":49428016,"html_url":"https://github.com/manastech/crystal/pull/1859","diff_url":"https://github.com/manastech/crystal/pull/1859.diff","patch_url":"https://github.com/manastech/crystal/pull/1859.patch","issue_url":"https://api.github.com/repos/manastech/crystal/issues/1859","number":1859,"state":"open","locked":false,"title":"Add Array#bsearch, Array#bsearch_index, Range#bsearch","user":{"login":"cielavenir","id":1495368,"avatar_url":"https://avatars.githubusercontent.com/u/1495368?v=3","gravatar_id":"","url":"https://api.github.com/users/cielavenir","html_url":"https://github.com/cielavenir","followers_url":"https://api.github.com/users/cielavenir/followers","following_url":"https://api.github.com/users/cielavenir/following{/other_user}","gists_url":"https://api.github.com/users/cielavenir/gists{/gist_id}","starred_url":"https://api.github.com/users/cielavenir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cielavenir/subscriptions","organizations_url":"https://api.github.com/users/cielavenir/orgs","repos_url":"https://api.github.com/users/cielavenir/repos","events_url":"https://api.github.com/users/cielavenir/events{/privacy}","received_events_url":"https://api.github.com/users/cielavenir/received_events","type":"User","site_admin":false},"body":"Currently Crystal lacks binary search, which is a great feature of Ruby 2.0+.\r\n\r\nI have (partially) ported https://github.com/marcandre/backports/blob/master/lib/backports/2.0.0/range/bsearch.rb .\r\nThe only point is that current port lacks Float support, which requires reinterpreting Float64 as Int64.\r\n\r\nAnd, `->{ (pointerof(midpoint) as Pointer(Int64)).value }.call` caused\r\n```\r\nError: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/manastech/crystal/issues\r\n```\r\n\r\nAnyway, the Int version works flawlessly. How do you think of this pull request?\r\nCurrently it is also available as https://github.com/cielavenir/crystal-bsearch shard and the spec will be ported after approval (I'll need to fix the indent).\r\n","created_at":"2015-11-02T12:53:46Z","updated_at":"2015-11-02T16:19:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c7f5298863a9b5a7c355f590bbb37cbcdd0a040d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/manastech/crystal/pulls/1859/commits","review_comments_url":"https://api.github.com/repos/manastech/crystal/pulls/1859/comments","review_comment_url":"https://api.github.com/repos/manastech/crystal/pulls/comments{/number}","comments_url":"https://api.github.com/repos/manastech/crystal/issues/1859/comments","statuses_url":"https://api.github.com/repos/manastech/crystal/statuses/1da57ffaad9a1ce1581edbd56c27d10aebae20f3","head":{"label":"cielavenir:bsearch","ref":"bsearch","sha":"1da57ffaad9a1ce1581edbd56c27d10aebae20f3","user":{"login":"cielavenir","id":1495368,"avatar_url":"https://avatars.githubusercontent.com/u/1495368?v=3","gravatar_id":"","url":"https://api.github.com/users/cielavenir","html_url":"https://github.com/cielavenir","followers_url":"https://api.github.com/users/cielavenir/followers","following_url":"https://api.github.com/users/cielavenir/following{/other_user}","gists_url":"https://api.github.com/users/cielavenir/gists{/gist_id}","starred_url":"https://api.github.com/users/cielavenir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cielavenir/subscriptions","organizations_url":"https://api.github.com/users/cielavenir/orgs","repos_url":"https://api.github.com/users/cielavenir/repos","events_url":"https://api.github.com/users/cielavenir/events{/privacy}","received_events_url":"https://api.github.com/users/cielavenir/received_events","type":"User","site_admin":false},"repo":{"id":45147300,"name":"crystal","full_name":"cielavenir/crystal","owner":{"login":"cielavenir","id":1495368,"avatar_url":"https://avatars.githubusercontent.com/u/1495368?v=3","gravatar_id":"","url":"https://api.github.com/users/cielavenir","html_url":"https://github.com/cielavenir","followers_url":"https://api.github.com/users/cielavenir/followers","following_url":"https://api.github.com/users/cielavenir/following{/other_user}","gists_url":"https://api.github.com/users/cielavenir/gists{/gist_id}","starred_url":"https://api.github.com/users/cielavenir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cielavenir/subscriptions","organizations_url":"https://api.github.com/users/cielavenir/orgs","repos_url":"https://api.github.com/users/cielavenir/repos","events_url":"https://api.github.com/users/cielavenir/events{/privacy}","received_events_url":"https://api.github.com/users/cielavenir/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cielavenir/crystal","description":"The Crystal Programming Language","fork":true,"url":"https://api.github.com/repos/cielavenir/crystal","forks_url":"https://api.github.com/repos/cielavenir/crystal/forks","keys_url":"https://api.github.com/repos/cielavenir/crystal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cielavenir/crystal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cielavenir/crystal/teams","hooks_url":"https://api.github.com/repos/cielavenir/crystal/hooks","issue_events_url":"https://api.github.com/repos/cielavenir/crystal/issues/events{/number}","events_url":"https://api.github.com/repos/cielavenir/crystal/events","assignees_url":"https://api.github.com/repos/cielavenir/crystal/assignees{/user}","branches_url":"https://api.github.com/repos/cielavenir/crystal/branches{/branch}","tags_url":"https://api.github.com/repos/cielavenir/crystal/tags","blobs_url":"https://api.github.com/repos/cielavenir/crystal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cielavenir/crystal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cielavenir/crystal/git/refs{/sha}","trees_url":"https://api.github.com/repos/cielavenir/crystal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cielavenir/crystal/statuses/{sha}","languages_url":"https://api.github.com/repos/cielavenir/crystal/languages","stargazers_url":"https://api.github.com/repos/cielavenir/crystal/stargazers","contributors_url":"https://api.github.com/repos/cielavenir/crystal/contributors","subscribers_url":"https://api.github.com/repos/cielavenir/crystal/subscribers","subscription_url":"https://api.github.com/repos/cielavenir/crystal/subscription","commits_url":"https://api.github.com/repos/cielavenir/crystal/commits{/sha}","git_commits_url":"https://api.github.com/repos/cielavenir/crystal/git/commits{/sha}","comments_url":"https://api.github.com/repos/cielavenir/crystal/comments{/number}","issue_comment_url":"https://api.github.com/repos/cielavenir/crystal/issues/comments{/number}","contents_url":"https://api.github.com/repos/cielavenir/crystal/contents/{+path}","compare_url":"https://api.github.com/repos/cielavenir/crystal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cielavenir/crystal/merges","archive_url":"https://api.github.com/repos/cielavenir/crystal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cielavenir/crystal/downloads","issues_url":"https://api.github.com/repos/cielavenir/crystal/issues{/number}","pulls_url":"https://api.github.com/repos/cielavenir/crystal/pulls{/number}","milestones_url":"https://api.github.com/repos/cielavenir/crystal/milestones{/number}","notifications_url":"https://api.github.com/repos/cielavenir/crystal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cielavenir/crystal/labels{/name}","releases_url":"https://api.github.com/repos/cielavenir/crystal/releases{/id}","created_at":"2015-10-28T23:10:44Z","updated_at":"2015-10-28T23:10:51Z","pushed_at":"2015-11-02T12:47:38Z","git_url":"git://github.com/cielavenir/crystal.git","ssh_url":"git@github.com:cielavenir/crystal.git","clone_url":"https://github.com/cielavenir/crystal.git","svn_url":"https://github.com/cielavenir/crystal","homepage":"http://crystal-lang.org","size":34399,"stargazers_count":0,"watchers_count":0,"language":"Crystal","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":"manastech:master","ref":"master","sha":"6c52fa3f384f8128ddecf8a7b7033abae52c44a2","user":{"login":"manastech","id":1354950,"avatar_url":"https://avatars.githubusercontent.com/u/1354950?v=3","gravatar_id":"","url":"https://api.github.com/users/manastech","html_url":"https://github.com/manastech","followers_url":"https://api.github.com/users/manastech/followers","following_url":"https://api.github.com/users/manastech/following{/other_user}","gists_url":"https://api.github.com/users/manastech/gists{/gist_id}","starred_url":"https://api.github.com/users/manastech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manastech/subscriptions","organizations_url":"https://api.github.com/users/manastech/orgs","repos_url":"https://api.github.com/users/manastech/repos","events_url":"https://api.github.com/users/manastech/events{/privacy}","received_events_url":"https://api.github.com/users/manastech/received_events","type":"Organization","site_admin":false},"repo":{"id":6887813,"name":"crystal","full_name":"manastech/crystal","owner":{"login":"manastech","id":1354950,"avatar_url":"https://avatars.githubusercontent.com/u/1354950?v=3","gravatar_id":"","url":"https://api.github.com/users/manastech","html_url":"https://github.com/manastech","followers_url":"https://api.github.com/users/manastech/followers","following_url":"https://api.github.com/users/manastech/following{/other_user}","gists_url":"https://api.github.com/users/manastech/gists{/gist_id}","starred_url":"https://api.github.com/users/manastech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manastech/subscriptions","organizations_url":"https://api.github.com/users/manastech/orgs","repos_url":"https://api.github.com/users/manastech/repos","events_url":"https://api.github.com/users/manastech/events{/privacy}","received_events_url":"https://api.github.com/users/manastech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/manastech/crystal","description":"The Crystal Programming Language","fork":false,"url":"https://api.github.com/repos/manastech/crystal","forks_url":"https://api.github.com/repos/manastech/crystal/forks","keys_url":"https://api.github.com/repos/manastech/crystal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/manastech/crystal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/manastech/crystal/teams","hooks_url":"https://api.github.com/repos/manastech/crystal/hooks","issue_events_url":"https://api.github.com/repos/manastech/crystal/issues/events{/number}","events_url":"https://api.github.com/repos/manastech/crystal/events","assignees_url":"https://api.github.com/repos/manastech/crystal/assignees{/user}","branches_url":"https://api.github.com/repos/manastech/crystal/branches{/branch}","tags_url":"https://api.github.com/repos/manastech/crystal/tags","blobs_url":"https://api.github.com/repos/manastech/crystal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/manastech/crystal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/manastech/crystal/git/refs{/sha}","trees_url":"https://api.github.com/repos/manastech/crystal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/manastech/crystal/statuses/{sha}","languages_url":"https://api.github.com/repos/manastech/crystal/languages","stargazers_url":"https://api.github.com/repos/manastech/crystal/stargazers","contributors_url":"https://api.github.com/repos/manastech/crystal/contributors","subscribers_url":"https://api.github.com/repos/manastech/crystal/subscribers","subscription_url":"https://api.github.com/repos/manastech/crystal/subscription","commits_url":"https://api.github.com/repos/manastech/crystal/commits{/sha}","git_commits_url":"https://api.github.com/repos/manastech/crystal/git/commits{/sha}","comments_url":"https://api.github.com/repos/manastech/crystal/comments{/number}","issue_comment_url":"https://api.github.com/repos/manastech/crystal/issues/comments{/number}","contents_url":"https://api.github.com/repos/manastech/crystal/contents/{+path}","compare_url":"https://api.github.com/repos/manastech/crystal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/manastech/crystal/merges","archive_url":"https://api.github.com/repos/manastech/crystal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/manastech/crystal/downloads","issues_url":"https://api.github.com/repos/manastech/crystal/issues{/number}","pulls_url":"https://api.github.com/repos/manastech/crystal/pulls{/number}","milestones_url":"https://api.github.com/repos/manastech/crystal/milestones{/number}","notifications_url":"https://api.github.com/repos/manastech/crystal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/manastech/crystal/labels{/name}","releases_url":"https://api.github.com/repos/manastech/crystal/releases{/id}","created_at":"2012-11-27T17:32:32Z","updated_at":"2015-11-02T13:31:08Z","pushed_at":"2015-11-02T12:53:46Z","git_url":"git://github.com/manastech/crystal.git","ssh_url":"git@github.com:manastech/crystal.git","clone_url":"https://github.com/manastech/crystal.git","svn_url":"https://github.com/manastech/crystal","homepage":"http://crystal-lang.org","size":49389,"stargazers_count":3667,"watchers_count":3667,"language":"Crystal","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":287,"mirror_url":null,"open_issues_count":247,"forks":287,"open_issues":247,"watchers":3667,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/manastech/crystal/pulls/1859"},"html":{"href":"https://github.com/manastech/crystal/pull/1859"},"issue":{"href":"https://api.github.com/repos/manastech/crystal/issues/1859"},"comments":{"href":"https://api.github.com/repos/manastech/crystal/issues/1859/comments"},"review_comments":{"href":"https://api.github.com/repos/manastech/crystal/pulls/1859/comments"},"review_comment":{"href":"https://api.github.com/repos/manastech/crystal/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/manastech/crystal/pulls/1859/commits"},"statuses":{"href":"https://api.github.com/repos/manastech/crystal/statuses/1da57ffaad9a1ce1581edbd56c27d10aebae20f3"}}}}