splitting.monotonic: a bit faster.

db4
John Benediktsson 2015-07-17 14:23:50 -07:00
parent 743928ae7d
commit 39055423ce
1 changed files with 7 additions and 7 deletions

View File

@ -7,19 +7,19 @@ IN: splitting.monotonic
<PRIVATE
:: ((monotonic-split)) ( seq quot slice-quot n -- pieces )
V{ } clone :> accum
V{ 0 } clone :> accum
0 0 seq [ ] [
0 seq [ ] [
[ 1 + ] 2dip [
quot call [
[ seq slice-quot call accum push ] keep dup
] unless
quot call [ dup accum push ] unless
] keep
] map-reduce drop
n = [ drop ] [ n seq slice-quot call accum push ] if
n = [ n accum push ] unless
accum { } like ; inline
accum dup rest-slice [
seq slice-quot call
] { } 2map-as ; inline
: (monotonic-split) ( seq quot slice-quot -- pieces )
pick length [ 3drop { } ] [ ((monotonic-split)) ] if-zero ; inline