Move monotonic-split to splitting.monotonic

db4
Slava Pestov 2008-12-17 20:04:41 -06:00
parent cd5ae48670
commit e7f35881ac
5 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1 @@
Doug Coleman

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
Split a sequence into monotonically-increasing subsequences

View File

@ -0,0 +1,2 @@
algorithms
sequences