Gestionnaire de fichiers - Editer - /opt/cpanel/ea-ruby24/root/usr/share/ri/system/Array/bsearch-i.ri
Arrière
U:RDoc::AnyMethod[iI"bsearch:ETI"Array#bsearch;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"GBy using binary search, finds a value from this array which meets ;TI"Fthe given condition in O(log n) where n is the size of the array.;To:RDoc::Markup::BlankLine o; ; [I"GYou can use this method in two use cases: a find-minimum mode and ;TI"Ia find-any mode. In either case, the elements of the array must be ;TI"4monotone (or sorted) with respect to the block.;T@o; ; [I"HIn find-minimum mode (this is a good choice for typical use case), ;TI"Gthe block must return true or false, and there must be an index i ;TI""(0 <= i <= ary.size) so that:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"Fthe block returns false for any element whose index is less than ;TI"i, and;To;;0; [o; ; [I"Cthe block returns true for any element whose index is greater ;TI"than or equal to i.;T@o; ; [I"GThis method returns the i-th element. If i is equal to ary.size, ;TI"it returns nil.;T@o:RDoc::Markup::Verbatim; [ I"ary = [0, 4, 7, 10, 12] ;TI"'ary.bsearch {|x| x >= 4 } #=> 4 ;TI"'ary.bsearch {|x| x >= 6 } #=> 7 ;TI"'ary.bsearch {|x| x >= -1 } #=> 0 ;TI")ary.bsearch {|x| x >= 100 } #=> nil ;T:@format0o; ; [I"GIn find-any mode (this behaves like libc's bsearch(3)), the block ;TI"Amust return a number, and there must be two indices i and j ;TI"'(0 <= i <= j <= ary.size) so that:;T@o;; ;;[o;;0; [o; ; [I"Bthe block returns a positive number for ary[k] if 0 <= k < i,;To;;0; [o; ; [I"9the block returns zero for ary[k] if i <= k < j, and;To;;0; [o; ; [I"7the block returns a negative number for ary[k] if ;TI"j <= k < ary.size.;T@o; ; [I"GUnder this condition, this method returns any element whose index ;TI"Eis within i...j. If i is equal to j (i.e., there is no element ;TI"8that satisfies the block), this method returns nil.;T@o;; [ I"ary = [0, 4, 7, 10, 12] ;TI"*# try to find v such that 4 <= v < 8 ;TI"-ary.bsearch {|x| 1 - x / 4 } #=> 4 or 7 ;TI"+# try to find v such that 8 <= v < 10 ;TI"*ary.bsearch {|x| 4 - x / 2 } #=> 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"array.c;T:0@omit_headings_from_table_of_contents_below0I"'ary.bsearch {|x| block } -> elem ;T0[ I"();T@[FI" Array;TcRDoc::NormalClass00
| ver. 1.4 |
Github
|
.
| PHP 8.0.30 | Génération de la page: 0.02 |
proxy
|
phpinfo
|
Réglages