factor/library/collections/sequence-sort.facts

28 lines
1.6 KiB
Plaintext
Raw Normal View History

IN: sequences
2006-01-09 01:34:23 -05:00
USING: help kernel words ;
2006-08-16 21:55:53 -04:00
HELP: sort
{ $values { "seq" "a sequence" } { "quot" "a comparator quotation" } { "sortedseq" "a new sorted sequence" } }
{ $description "Sorts the elements into a new sequence of the same class as " { $snippet "seq" } "." } ;
2006-08-16 21:55:53 -04:00
HELP: nsort
{ $values { "seq" "a mutable sequence" } { "quot" "a comparator quotation" } }
{ $description "Sorts the sequence in-place." }
{ $side-effects "seq" } ;
2006-08-16 21:55:53 -04:00
HELP: natural-sort
{ $values { "seq" "a sequence of real numbers" } { "sortedseq" "a new sorted sequence" } }
2006-01-09 01:34:23 -05:00
{ $description "Sorts a sequence of objects in natural order using the " { $link <=> } " word." } ;
2006-08-16 21:55:53 -04:00
HELP: binsearch
{ $values { "elt" "an object" } { "seq" "a sorted sequence" } { "quot" "a comparator quotation" } { "i" "the index of the search result" } }
{ $description "Given a sequence that is sorted with respect to the " { $snippet "quot" } " comparator, searches for an element equal to " { $snippet "elt" } ", or failing that, the greatest element smaller than " { $snippet "elt" } ". Comparison is performed with " { $snippet "quot" } "."
$terpri
"Outputs -1 if the sequence is empty. If the sequence has at least one element, this word always outputs a valid index." } ;
2006-08-16 21:55:53 -04:00
HELP: binsearch*
{ $values { "elt" "an object" } { "seq" "a sorted sequence" } { "quot" "a comparator quotation" } { "result" "the search result" } }
{ $description "Variant of " { $link binsearch } " which outputs the found element rather than its index in the sequence."
$terpri
"Outputs " { $link f } " if the sequence is empty. If the sequence has at least one element, this word always outputs a sequence element." } ;