Merge branch 'master' of git://github.com/Blei/factor
commit
0beec6befc
|
@ -21,7 +21,7 @@ M: circular length seq>> length ;
|
|||
|
||||
M: circular virtual@ circular-wrap seq>> ;
|
||||
|
||||
M: circular virtual-seq seq>> ;
|
||||
M: circular virtual-exemplar seq>> ;
|
||||
|
||||
: change-circular-start ( n circular -- )
|
||||
#! change start to (start + n) mod length
|
||||
|
|
|
@ -8,7 +8,7 @@ TUPLE: column seq col ;
|
|||
|
||||
C: <column> column
|
||||
|
||||
M: column virtual-seq seq>> ;
|
||||
M: column virtual-exemplar seq>> ;
|
||||
M: column virtual@ [ col>> swap ] [ seq>> ] bi nth bounds-check ;
|
||||
M: column length seq>> length ;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ TUPLE: simple-cord
|
|||
M: simple-cord length
|
||||
[ first>> length ] [ second>> length ] bi + ; inline
|
||||
|
||||
M: simple-cord virtual-seq first>> ; inline
|
||||
M: simple-cord virtual-exemplar first>> ; inline
|
||||
|
||||
M: simple-cord virtual@
|
||||
2dup first>> length <
|
||||
|
@ -28,7 +28,7 @@ M: multi-cord virtual@
|
|||
seqs>> [ first <=> ] with search nip
|
||||
[ first - ] [ second ] bi ; inline
|
||||
|
||||
M: multi-cord virtual-seq
|
||||
M: multi-cord virtual-exemplar
|
||||
seqs>> [ f ] [ first second ] if-empty ; inline
|
||||
|
||||
: <cord> ( seqs -- cord )
|
||||
|
|
|
@ -117,7 +117,7 @@ M: blas-vector-base equal?
|
|||
|
||||
M: blas-vector-base length
|
||||
length>> ;
|
||||
M: blas-vector-base virtual-seq
|
||||
M: blas-vector-base virtual-exemplar
|
||||
(blas-direct-array) ;
|
||||
M: blas-vector-base virtual@
|
||||
[ inc>> * ] [ nip (blas-direct-array) ] 2bi ;
|
||||
|
|
|
@ -20,7 +20,7 @@ HELP: merged
|
|||
|
||||
HELP: <merged> ( seqs -- merged )
|
||||
{ $values { "seqs" "a sequence of sequences to merge" } { "merged" "a virtual sequence" } }
|
||||
{ $description "Creates an instance of the " { $link merged } " virtual sequence." }
|
||||
{ $description "Creates an instance of the " { $link merged } " virtual sequence. The length of the created virtual sequences is the minimum length of the input sequences times the number of input sequences." }
|
||||
{ $see-also <2merged> <3merged> merge } ;
|
||||
|
||||
HELP: <2merged> ( seq1 seq2 -- merged )
|
||||
|
|
|
@ -15,3 +15,6 @@ IN: sequences.merged.tests
|
|||
[ 6 ] [ 5 { 1 2 3 } { 4 5 6 } <2merged> nth ] unit-test
|
||||
|
||||
[ 4 ] [ 4 { 1 2 } { 3 4 } { 5 6 } 3merge nth ] unit-test
|
||||
|
||||
[ "" ] [ "abcdefg" "" 2merge ] unit-test
|
||||
[ "a1b2" ] [ "abc" "12" <2merged> "" like ] unit-test
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
! Copyright (C) 2008 Alex Chapman
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors arrays kernel math sequences ;
|
||||
USING: accessors arrays kernel math math.order sequences
|
||||
sequences.private ;
|
||||
IN: sequences.merged
|
||||
|
||||
TUPLE: merged seqs ;
|
||||
|
@ -10,19 +11,21 @@ C: <merged> merged
|
|||
: <3merged> ( seq1 seq2 seq3 -- merged ) 3array <merged> ;
|
||||
|
||||
: merge ( seqs -- seq )
|
||||
dup <merged> swap first like ;
|
||||
[ <merged> ] keep first like ;
|
||||
|
||||
: 2merge ( seq1 seq2 -- seq )
|
||||
dupd <2merged> swap like ;
|
||||
[ <2merged> ] 2keep drop like ;
|
||||
|
||||
: 3merge ( seq1 seq2 seq3 -- seq )
|
||||
pick [ <3merged> ] dip like ;
|
||||
[ <3merged> ] 3keep 2drop like ;
|
||||
|
||||
M: merged length seqs>> [ length ] map sum ;
|
||||
M: merged length
|
||||
seqs>> [ [ length ] [ min ] map-reduce ] [ length ] bi * ; inline
|
||||
|
||||
M: merged virtual@ ( n seq -- n' seq' )
|
||||
seqs>> [ length /mod ] [ nth ] bi ;
|
||||
seqs>> [ length /mod ] [ nth-unsafe ] bi ; inline
|
||||
|
||||
M: merged virtual-seq ( merged -- seq ) [ ] { } map-as ;
|
||||
M: merged virtual-exemplar ( merged -- seq )
|
||||
seqs>> [ f ] [ first ] if-empty ; inline
|
||||
|
||||
INSTANCE: merged virtual-sequence
|
||||
|
|
|
@ -61,7 +61,7 @@ INSTANCE: curry immutable-sequence
|
|||
M: compose length
|
||||
[ first>> length ] [ second>> length ] bi + ;
|
||||
|
||||
M: compose virtual-seq first>> ;
|
||||
M: compose virtual-exemplar first>> ;
|
||||
|
||||
M: compose virtual@
|
||||
2dup first>> length < [
|
||||
|
|
|
@ -1175,17 +1175,17 @@ HELP: partition
|
|||
}
|
||||
} ;
|
||||
|
||||
HELP: virtual-seq
|
||||
HELP: virtual-exemplar
|
||||
{ $values
|
||||
{ "seq" sequence }
|
||||
{ "seq'" sequence } }
|
||||
{ $description "Part of the virtual sequence protocol, this word is used to return an underlying array from which to look up a value at an index given by " { $link virtual@ } "." } ;
|
||||
{ $description "Part of the virtual sequence protocol, this word is used to return an exemplar of the underlying storage. This is used in words like " { $link new-sequence } "." } ;
|
||||
|
||||
HELP: virtual@
|
||||
{ $values
|
||||
{ "n" integer } { "seq" sequence }
|
||||
{ "n'" integer } { "seq'" sequence } }
|
||||
{ $description "Part of the sequence protocol, this word translates the input index " { $snippet "n" } " into an index into the underlying storage returned by " { $link virtual-seq } "." } ;
|
||||
{ $description "Part of the sequence protocol, this word translates the input index " { $snippet "n" } " into an index and the underlying storage this index points into." } ;
|
||||
|
||||
HELP: 2map-reduce
|
||||
{ $values
|
||||
|
@ -1397,9 +1397,9 @@ $nl
|
|||
ARTICLE: "virtual-sequences-protocol" "Virtual sequence protocol"
|
||||
"Virtual sequences must know their length:"
|
||||
{ $subsections length }
|
||||
"The underlying sequence to look up a value in:"
|
||||
{ $subsections virtual-seq }
|
||||
"The index of the value in the underlying sequence:"
|
||||
"An exemplar of the underlying storage:"
|
||||
{ $subsections virtual-exemplar }
|
||||
"The index and the underlying storage where the value is located:"
|
||||
{ $subsections virtual@ } ;
|
||||
|
||||
ARTICLE: "virtual-sequences" "Virtual sequences"
|
||||
|
|
|
@ -182,15 +182,15 @@ PRIVATE>
|
|||
2dup bounds-check? [ nth-unsafe ] [ 2drop f ] if ; inline
|
||||
|
||||
MIXIN: virtual-sequence
|
||||
GENERIC: virtual-seq ( seq -- seq' )
|
||||
GENERIC: virtual-exemplar ( seq -- seq' )
|
||||
GENERIC: virtual@ ( n seq -- n' seq' )
|
||||
|
||||
M: virtual-sequence nth virtual@ nth ; inline
|
||||
M: virtual-sequence set-nth virtual@ set-nth ; inline
|
||||
M: virtual-sequence nth-unsafe virtual@ nth-unsafe ; inline
|
||||
M: virtual-sequence set-nth-unsafe virtual@ set-nth-unsafe ; inline
|
||||
M: virtual-sequence like virtual-seq like ; inline
|
||||
M: virtual-sequence new-sequence virtual-seq new-sequence ; inline
|
||||
M: virtual-sequence like virtual-exemplar like ; inline
|
||||
M: virtual-sequence new-sequence virtual-exemplar new-sequence ; inline
|
||||
|
||||
INSTANCE: virtual-sequence sequence
|
||||
|
||||
|
@ -199,7 +199,7 @@ TUPLE: reversed { seq read-only } ;
|
|||
|
||||
C: <reversed> reversed
|
||||
|
||||
M: reversed virtual-seq seq>> ; inline
|
||||
M: reversed virtual-exemplar seq>> ; inline
|
||||
M: reversed virtual@ seq>> [ length swap - 1 - ] keep ; inline
|
||||
M: reversed length seq>> length ; inline
|
||||
|
||||
|
@ -231,7 +231,7 @@ TUPLE: slice-error from to seq reason ;
|
|||
check-slice
|
||||
slice boa ; inline
|
||||
|
||||
M: slice virtual-seq seq>> ; inline
|
||||
M: slice virtual-exemplar seq>> ; inline
|
||||
|
||||
M: slice virtual@ [ from>> + ] [ seq>> ] bi ; inline
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors alien.c-types alien.strings assocs byte-arrays
|
||||
combinators continuations destructors fry io.encodings.8-bit
|
||||
io io.encodings.string io.encodings.utf8 kernel math
|
||||
io io.encodings.string io.encodings.utf8 kernel locals math
|
||||
namespaces prettyprint sequences classes.struct
|
||||
strings threads curses.ffi ;
|
||||
IN: curses
|
||||
|
|
|
@ -21,7 +21,7 @@ TUPLE: 1modified < modified seq ;
|
|||
M: modified length seq>> length ;
|
||||
M: modified set-length seq>> set-length ;
|
||||
|
||||
M: 1modified virtual-seq seq>> ;
|
||||
M: 1modified virtual-exemplar seq>> ;
|
||||
|
||||
TUPLE: scaled < 1modified c ;
|
||||
C: <scaled> scaled
|
||||
|
@ -71,7 +71,8 @@ M: summed modified-set-nth ( elt n seq -- ) immutable ;
|
|||
M: summed set-length ( n seq -- )
|
||||
seqs>> [ set-length ] with each ;
|
||||
|
||||
M: summed virtual-seq ( summed -- seq ) [ ] { } map-as ;
|
||||
M: summed virtual-exemplar ( summed -- seq )
|
||||
seqs>> [ f ] [ first ] if-empty ;
|
||||
|
||||
: <2summed> ( seq seq -- summed-seq ) 2array <summed> ;
|
||||
: <3summed> ( seq seq seq -- summed-seq ) 3array <summed> ;
|
||||
|
|
|
@ -16,6 +16,6 @@ M: repeating set-length (>>len) ;
|
|||
|
||||
M: repeating virtual@ ( n seq -- n' seq' ) circular>> ;
|
||||
|
||||
M: repeating virtual-seq circular>> ;
|
||||
M: repeating virtual-exemplar circular>> ;
|
||||
|
||||
INSTANCE: repeating virtual-sequence
|
||||
|
|
Loading…
Reference in New Issue