Merge branch 'master' into new_optimizer

db4
Slava Pestov 2008-08-13 14:32:48 -05:00
commit 6a3eb0b7ca
3 changed files with 33 additions and 22 deletions

View File

@ -88,6 +88,14 @@ M:: disjoint-set equate ( a b disjoint-set -- )
disjoint-set link-sets disjoint-set link-sets
] if ; ] if ;
: equate-all-with ( seq a disjoint-set -- )
'[ , , equate ] each ;
: equate-all ( seq disjoint-set -- )
over dup empty? [ 2drop ] [
[ unclip-slice ] dip equate-all-with
] if ;
M: disjoint-set clone M: disjoint-set clone
[ parents>> ] [ ranks>> ] [ counts>> ] tri [ clone ] tri@ [ parents>> ] [ ranks>> ] [ counts>> ] tri [ clone ] tri@
disjoint-set boa ; disjoint-set boa ;

View File

@ -1,21 +1,27 @@
USING: help.syntax help.markup ; USING: help.syntax help.markup arrays sequences ;
IN: math.ranges IN: math.ranges
ARTICLE: "ranges" "Ranges" ARTICLE: "ranges" "Ranges"
"A " { $emphasis "range" } " is a virtual sequence with real number elements "
"A " { $emphasis "range" } " is a virtual sequence with real elements " "ranging from " { $emphasis "a" } " to " { $emphasis "b" } " by " { $emphasis "step" } "."
"ranging from " { $emphasis "a" } " to " { $emphasis "b" } " by " { $emphasis "step" } "." $nl
"The class of ranges:"
$nl { $subsection range }
"Creating ranges with integer end-points. The standard mathematical convention is used, where " { $snippet "(" } " or " { $snippet ")" } " denotes that the end-point itself " { $emphasis "is not" } " part of the range; " { $snippet "[" } " or " { $snippet "]" } " denotes that the end-point " { $emphasis "is" } " part of the range:"
"Creating ranges:" { $subsection [a,b] }
{ $subsection (a,b] }
{ $subsection <range> } { $subsection [a,b) }
{ $subsection [a,b] } { $subsection (a,b) }
{ $subsection (a,b] } { $subsection [0,b] }
{ $subsection [a,b) } { $subsection [1,b] }
{ $subsection (a,b) } { $subsection [0,b) }
{ $subsection [0,b] } "Creating general ranges:"
{ $subsection [1,b] } { $subsection <range> }
{ $subsection [0,b) } ; "Ranges are most frequently used with sequence combinators as a means of iterating over integers. For example,"
{ $code
"3 10 [a,b] [ sqrt ] map"
}
"A range can be converted into a concrete sequence using a word such as " { $link >array } ". In most cases this is unnecessary since ranges implement the sequence protocol already. It is necessary if a mutable sequence is needed, for use with words such as " { $link set-nth } " or " { $link change-each } "." ;
ABOUT: "ranges"

View File

@ -1,7 +1,7 @@
! Copyright (c) 2007, 2008 Slava Pestov, Doug Coleman, Aaron Schaefer. ! Copyright (c) 2007, 2008 Slava Pestov, Doug Coleman, Aaron Schaefer.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: assocs kernel math math.order math.ranges mirrors USING: assocs kernel math math.order math.ranges mirrors
namespaces sequences sorting ; namespaces sequences sequences.lib sorting ;
IN: math.combinatorics IN: math.combinatorics
<PRIVATE <PRIVATE
@ -27,9 +27,6 @@ IN: math.combinatorics
: permutation-indices ( n seq -- permutation ) : permutation-indices ( n seq -- permutation )
length [ factoradic ] dip 0 pad-left >permutation ; length [ factoradic ] dip 0 pad-left >permutation ;
: reorder ( seq indices -- seq )
[ [ over nth , ] each drop ] { } make ;
PRIVATE> PRIVATE>
: factorial ( n -- n! ) : factorial ( n -- n! )
@ -42,7 +39,7 @@ PRIVATE>
twiddle [ nPk ] keep factorial / ; twiddle [ nPk ] keep factorial / ;
: permutation ( n seq -- seq ) : permutation ( n seq -- seq )
tuck permutation-indices reorder ; tuck permutation-indices nths ;
: all-permutations ( seq -- seq ) : all-permutations ( seq -- seq )
[ [