⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.25
Server IP:
109.199.105.153
Server:
Linux connect.inboxifs.com 5.15.0-152-generic #162-Ubuntu SMP Wed Jul 23 09:48:42 UTC 2025 x86_64
Server Software:
Apache
PHP Version:
8.2.29
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
ri
/
3.0.0
/
system
/
Array
/
View File Name :
bsearch-i.ri
U:RDoc::AnyMethod[iI"bsearch:ETI"Array#bsearch;TF:publico:RDoc::Markup::Document:@parts[+o:RDoc::Markup::Paragraph; [I"AReturns an element from +self+ selected by a binary search. ;TI"6+self+ should be sorted, but this is not checked.;To:RDoc::Markup::BlankLine o; ; [I"GBy using binary search, finds a value from this array which meets ;TI"Qthe given condition in <tt>O(log n)</tt> where +n+ is the size of the array.;T@o; ; [I" There are two search modes:;To:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"I<b>Find-minimum mode</b>: the block should return +true+ or +false+.;To;;0; [o; ; [I"C<b>Find-any mode</b>: the block should return a numeric value.;T@o; ; [I"UThe block should not mix the modes by and sometimes returning +true+ or +false+ ;TI"Fand sometimes returning a numeric value, but this is not checked.;T@o; ; [I"<b>Find-Minimum Mode</b>;T@o; ; [I"GIn find-minimum mode, the block always returns +true+ or +false+. ;TI":The further requirement (though not checked) is that ;TI"0there are no indexes +i+ and +j+ such that:;To;; ;;[o;;0; [o; ; [I"&<tt>0 <= i < j <= self.size</tt>.;To;;0; [o; ; [I"TThe block returns +true+ for <tt>self[i]</tt> and +false+ for <tt>self[j]</tt>.;T@o; ; [I"eIn find-minimum mode, method bsearch returns the first element for which the block returns true.;T@o; ; [I"Examples:;To:RDoc::Markup::Verbatim; [ I"a = [0, 4, 7, 10, 12] ;TI"$a.bsearch {|x| x >= 4 } # => 4 ;TI"$a.bsearch {|x| x >= 6 } # => 7 ;TI"%a.bsearch {|x| x >= -1 } # => 0 ;TI"(a.bsearch {|x| x >= 100 } # => nil ;T:@format0o; ; [I"KLess formally: the block is such that all +false+-evaluating elements ;TI",precede all +true+-evaluating elements.;T@o; ; [I"5These make sense as blocks in find-minimum mode:;To;; [ I"a = [0, 4, 7, 10, 12] ;TI">a.map {|x| x >= 4 } # => [false, true, true, true, true] ;TI"?a.map {|x| x >= 6 } # => [false, false, true, true, true] ;TI">a.map {|x| x >= -1 } # => [true, true, true, true, true] ;TI"Da.map {|x| x >= 100 } # => [false, false, false, false, false] ;T;0o; ; [I"This would not make sense:;To;; [I"a = [0, 4, 7, 10, 12] ;TI"Aa.map {|x| x == 7 } # => [false, false, true, false, false] ;T;0o; ; [I"<b>Find-Any Mode</b>;T@o; ; [I"AIn find-any mode, the block always returns a numeric value. ;TI":The further requirement (though not checked) is that ;TI"0there are no indexes +i+ and +j+ such that:;To;; ;;[ o;;0; [o; ; [I"&<tt>0 <= i < j <= self.size</tt>.;To;;0; [o; ; [I"=The block returns a negative value for <tt>self[i]</tt> ;TI"/and a positive value for <tt>self[j]</tt>.;To;;0; [o; ; [I"WThe block returns a negative value for <tt>self[i]</tt> and zero <tt>self[j]</tt>.;To;;0; [o; ; [I"[The block returns zero for <tt>self[i]</tt> and a positive value for <tt>self[j]</tt>.;T@o; ; [I";In find-any mode, method bsearch returns some element ;TI"Lfor which the block returns zero, or +nil+ if no such element is found.;T@o; ; [I"Examples:;To;; [ I"a = [0, 4, 7, 10, 12] ;TI"1a.bsearch {|element| 7 <=> element } # => 7 ;TI"4a.bsearch {|element| -1 <=> element } # => nil ;TI"3a.bsearch {|element| 5 <=> element } # => nil ;TI"4a.bsearch {|element| 15 <=> element } # => nil ;T;0o; ; [I"+Less formally: the block is such that:;To;; ;;[o;;0; [o; ; [I"KAll positive-evaluating elements precede all zero-evaluating elements.;To;;0; [o; ; [I"OAll positive-evaluating elements precede all negative-evaluating elements.;To;;0; [o; ; [I"KAll zero-evaluating elements precede all negative-evaluating elements.;T@o; ; [I"1These make sense as blocks in find-any mode:;To;; [ I"a = [0, 4, 7, 10, 12] ;TI"=a.map {|element| 7 <=> element } # => [1, 1, 0, -1, -1] ;TI"Aa.map {|element| -1 <=> element } # => [-1, -1, -1, -1, -1] ;TI">a.map {|element| 5 <=> element } # => [1, 1, -1, -1, -1] ;TI"<a.map {|element| 15 <=> element } # => [1, 1, 1, 1, 1] ;T;0o; ; [I"This would not make sense:;To;; [I"a = [0, 4, 7, 10, 12] ;TI"=a.map {|element| element <=> 7 } # => [-1, -1, 0, 1, 1] ;T;0o; ; [I"-Returns an enumerator if no block given:;To;; [I"a = [0, 4, 7, 10, 12] ;TI"<a.bsearch # => #<Enumerator: [0, 4, 7, 10, 12]:bsearch>;T;0: @fileI"array.c;T:0@omit_headings_from_table_of_contents_below0I"Narray.bsearch {|element| ... } -> object array.bsearch -> new_enumerator ;T0[ I"();T@�FI" Array;TcRDoc::NormalClass00