Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9c063a5268ef
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7b4d194db451
Choose a head ref
  • 4 commits
  • 4 files changed
  • 1 contributor

Commits on Oct 24, 2014

  1. Removed debug logging.

    brixen committed Oct 24, 2014
    Copy the full SHA
    aff8843 View commit details
  2. Added specs for Array#bsearch.

    brixen committed Oct 24, 2014
    Copy the full SHA
    1cea12c View commit details
  3. Added Array#bsearch.

    brixen committed Oct 24, 2014
    Copy the full SHA
    b048dba View commit details
  4. Updated gems_list.txt.

    brixen committed Oct 24, 2014
    Copy the full SHA
    7b4d194 View commit details
Showing with 77 additions and 4 deletions.
  1. +3 −3 gems_list.txt
  2. +36 −0 kernel/common/array.rb
  3. +38 −0 spec/ruby/core/array/bsearch_spec.rb
  4. +0 −1 vm/builtin/stat.cpp
6 changes: 3 additions & 3 deletions gems_list.txt
Original file line number Diff line number Diff line change
@@ -2,10 +2,10 @@ bundler-1.7.4.gem
ffi2-generators-0.1.1.gem
json-1.8.1.gem
minitest-4.7.5.gem
racc-1.4.11.gem
racc-1.4.12.gem
rake-10.3.2.gem
rdoc-4.1.1.gem
rb-readline-0.5.1.gem
rdoc-4.1.2.gem
rubinius-ast-2.2.5.gem
rubinius-build_tools-2.0.0.gem
rubinius-compiler-2.2.1.gem
@@ -29,7 +29,7 @@ rubysl-continuation-2.0.0.gem
rubysl-coverage-2.0.3.gem
rubysl-csv-2.0.2.gem
rubysl-curses-2.0.1.gem
rubysl-date-2.0.6.gem
rubysl-date-2.0.8.gem
rubysl-delegate-2.0.1.gem
rubysl-digest-2.0.3.gem
rubysl-drb-2.0.1.gem
36 changes: 36 additions & 0 deletions kernel/common/array.rb
Original file line number Diff line number Diff line change
@@ -339,6 +339,42 @@ def assoc(obj)
nil
end

def bsearch
m = Rubinius::Mirror::Array.reflect self

tuple = m.tuple

min = start = m.start
max = total = start + m.total

last_true = nil
i = start + m.total / 2

while max > min and i >= start and i <= total
x = yield tuple.at(i)

return tuple.at(i) if x == 0

if x == false
min = i + 1
elsif x == true
last_true = i
max = i - 1
elsif x > 0
min = i + 1
else
max = i - 1
end

i = min + (max - min) / 2
end

return tuple.at(i) if max > min
return tuple.at(last_true) if last_true

nil
end

def clear
Rubinius.check_frozen

38 changes: 38 additions & 0 deletions spec/ruby/core/array/bsearch_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require File.expand_path('../../../spec_helper', __FILE__)

describe "Array#bsearch" do
context "with a block returning true or false" do
it "returns nil if the block returns false for every element" do
[0, 1, 2, 3].bsearch { |x| x > 3 }.should be_nil
end

it "returns element at zero if the block returns true for every element" do
[0, 1, 2, 3].bsearch { |x| x < 4 }.should == 0

end

it "returns the element at the smallest index for which block returns true" do
[0, 1, 3, 4].bsearch { |x| x >= 2 }.should == 3
end
end

context "with a block returning negative, zero, positive numbers" do
it "returns nil if the block returns less than zero for every element" do
[0, 1, 2, 3].bsearch { |x| x <=> 5 }.should be_nil
end

it "returns nil if the block returns greater than zero for every element" do
[0, 1, 2, 3].bsearch { |x| x <=> -1 }.should be_nil

end

it "returns nil if the block never returns zero" do
[0, 1, 3, 4].bsearch { |x| x <=> 2 }.should be_nil
end

it "returns an element at an index for which block returns true" do
result = [0, 1, 2, 3, 4].bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
[1, 2].should include(result)
end
end
end
1 change: 0 additions & 1 deletion vm/builtin/stat.cpp
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ namespace rubinius {
}

Fixnum* Stat::stat(STATE, String* p) {
utilities::logger::warn("stat: %s", p->c_str_null_safe(state));
path(state, p);
return Fixnum::from(::stat(p->c_str_null_safe(state), &st_));
}