U:RDoc::AnyMethod[iI" bsearch:ETI"Range#bsearch;TF: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"JBy using binary search, finds a value in range which meets the given ;TI"= 4 } #=> 1 ;TI"5(0...ary.size).bsearch {|i| ary[i] >= 6 } #=> 2 ;TI"5(0...ary.size).bsearch {|i| ary[i] >= 8 } #=> 3 ;TI"9(0...ary.size).bsearch {|i| ary[i] >= 100 } #=> nil ;TI" ;TI"E(0.0...Float::INFINITY).bsearch {|x| Math.log(x) >= 0 } #=> 1.0 ;T: @format0o; ; [I"GIn find-any mode (this behaves like libc's bsearch(3)), the block ;TI"Imust return a number, and there must be two values x and y (x <= y) ;TI" so that:;T@o; ; ;;[o;;0; [o; ; [I"8the block returns a positive number for v if v < x,;To;;0; [o; ; [I"4the block returns zero for v if x <= v < y, and;To;;0; [o; ; [I"9the block returns a negative number for v if y <= v.;T@o; ; [I"GThis method returns any value which is within the intersection of ;TI"Dthe given range and x...y (if any). If there is no value that ;TI"-satisfies the condition, it returns nil.;T@o;; [ I"#ary = [0, 100, 100, 100, 200] ;TI"6(0..4).bsearch {|i| 100 - ary[i] } #=> 1, 2 or 3 ;TI"0(0..4).bsearch {|i| 300 - ary[i] } #=> nil ;TI"0(0..4).bsearch {|i| 50 - ary[i] } #=> nil ;T;0o; ; [I"EYou must not mix the two modes at a time; the block must always ;TI"Areturn either true/false, or always return a number. It is ;TI"Cundefined which value is actually picked up at each iteration.;T: @fileI" range.c;T:0@omit_headings_from_table_of_contents_below0I"*rng.bsearch {|obj| block } -> value ;T0[I"();T@ZFI" Range;TcRDoc::NormalClass00