]> gitweb.factorcode.org Git - factor.git/blob - core/collections/sequence-sort.facts
93405fc60d327c678bc658c6fee4ad932732004d
[factor.git] / core / collections / sequence-sort.facts
1 IN: sequences
2 USING: help kernel words ;
3
4 HELP: sort
5 { $values { "seq" "a sequence" } { "quot" "a comparator quotation" } { "sortedseq" "a new sorted sequence" } }
6 { $description "Sorts the elements into a new sequence of the same class as " { $snippet "seq" } "." } ;
7
8 HELP: sort-keys
9 { $values { "seq" "a sequence of pairs" } { "sortedseq" "a new sorted sequence" } }
10 { $description "Sorts the elements comparing first elements of pairs using the " { $link <=> } " word." } ;
11
12 HELP: sort-values
13 { $values { "seq" "a sequence of pairs" } { "sortedseq" "a new sorted sequence" } }
14 { $description "Sorts the elements comparing second elements of pairs using the " { $link <=> } " word." } ;
15
16 HELP: nsort
17 { $values { "seq" "a mutable sequence" } { "quot" "a comparator quotation" } }
18 { $description "Sorts the sequence in-place." }
19 { $side-effects "seq" } ;
20
21 HELP: natural-sort
22 { $values { "seq" "a sequence of real numbers" } { "sortedseq" "a new sorted sequence" } }
23 { $description "Sorts a sequence of objects in natural order using the " { $link <=> } " word." } ;
24
25 HELP: binsearch
26 { $values { "elt" "an object" } { "seq" "a sorted sequence" } { "quot" "a comparator quotation" } { "i" "the index of the search result" } }
27 { $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" } "."
28 $terpri
29 "Outputs -1 if the sequence is empty. If the sequence has at least one element, this word always outputs a valid index." } ;
30
31 HELP: binsearch*
32 { $values { "elt" "an object" } { "seq" "a sorted sequence" } { "quot" "a comparator quotation" } { "result" "the search result" } }
33 { $description "Variant of " { $link binsearch } " which outputs the found element rather than its index in the sequence."
34 $terpri
35 "Outputs " { $link f } " if the sequence is empty. If the sequence has at least one element, this word always outputs a sequence element." } ;