Move monotonic-split to splitting.monotonic
parent
cd5ae48670
commit
e7f35881ac
|
@ -0,0 +1 @@
|
|||
Doug Coleman
|
|
@ -0,0 +1,8 @@
|
|||
IN: splitting.monotonic
|
||||
USING: tools.test math arrays kernel sequences ;
|
||||
|
||||
[ { { 1 } { -1 5 } { 2 4 } } ]
|
||||
[ { 1 -1 5 2 4 } [ < ] monotonic-split [ >array ] map ] unit-test
|
||||
[ { { 1 1 1 1 } { 2 2 } { 3 } { 4 } { 5 } { 6 6 6 } } ]
|
||||
[ { 1 1 1 1 2 2 3 4 5 6 6 6 } [ = ] monotonic-split [ >array ] map ] unit-test
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
! Copyright (C) 2008 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: make namespaces sequences kernel fry ;
|
||||
IN: splitting.monotonic
|
||||
|
||||
: ,, ( obj -- ) building get peek push ;
|
||||
: v, ( -- ) V{ } clone , ;
|
||||
: ,v ( -- ) building get dup peek empty? [ dup pop* ] when drop ;
|
||||
|
||||
: (monotonic-split) ( seq quot -- newseq )
|
||||
[
|
||||
[ dup unclip suffix ] dip
|
||||
v, '[ over ,, @ [ v, ] unless ] 2each ,v
|
||||
] { } make ; inline
|
||||
|
||||
: monotonic-split ( seq quot -- newseq )
|
||||
over empty? [ 2drop { } ] [ (monotonic-split) ] if ; inline
|
|
@ -0,0 +1 @@
|
|||
Split a sequence into monotonically-increasing subsequences
|
|
@ -0,0 +1,2 @@
|
|||
algorithms
|
||||
sequences
|
Loading…
Reference in New Issue