]> gitweb.factorcode.org Git - factor.git/commitdiff
binary-search: allow search to look into the stack.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 15 May 2023 21:27:44 +0000 (14:27 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 15 May 2023 21:27:44 +0000 (14:27 -0700)
basis/binary-search/binary-search-docs.factor
basis/binary-search/binary-search.factor

index 8ab9f7fc95b0302630458327dc975bca124995b0..76fc3187a8abbf4b5349b23a2791a6e3ce45fb53 100644 (file)
@@ -2,7 +2,7 @@ IN: binary-search
 USING: help.markup help.syntax sequences kernel math.order ;
 
 HELP: search
-{ $values { "seq" "a sorted sequence" } { "quot" { $quotation ( elt -- <=> ) } } { "i" "an index, or " { $link f } } { "elt" "an element, or " { $link f } } }
+{ $values { "seq" "a sorted sequence" } { "quot" { $quotation ( ... elt -- ... <=> ) } } { "i" "an index, or " { $link f } } { "elt" "an element, or " { $link f } } }
 { $description "Performs a binary search on a sequence, calling the quotation to decide whether to end the search (" { $link +eq+ } "), search lower (" { $link +lt+ } ") or search higher (" { $link +gt+ } ")."
 $nl
 "If the sequence is non-empty, outputs the index and value of the closest match, which is either an element for which the quotation output " { $link +eq+ } ", or failing that, the least element for which the quotation output " { $link +lt+ } ", or if there were none of the above, the greatest element for which the quotation output " { $link +gt+ } "."
index da1434d94e7463f7533bd807b708937c77d38341..6db08af97cff035d26882b997008528131b704c5 100644 (file)
@@ -6,7 +6,7 @@ IN: binary-search
 
 <PRIVATE
 
-:: (search) ( seq from to quot: ( elt -- <=> ) -- i elt )
+:: (search) ( ... seq from to quot: ( ... elt -- ... <=> ) -- ... i elt )
     from to + 2/ :> midpoint@
     midpoint@ seq nth-unsafe :> midpoint
 
@@ -22,7 +22,7 @@ IN: binary-search
 
 PRIVATE>
 
-: search ( seq quot: ( elt -- <=> ) -- i elt )
+: search ( ... seq quot: ( ... elt -- ... <=> ) -- ... i elt )
     over empty? [ 2drop f f ] [ [ 0 over length ] dip (search) ] if ; inline
 
 GENERIC: natural-search ( obj seq -- i elt )