2008-05-18 22:25:58 -04:00
|
|
|
! Copyright (C) 2008 Alex Chapman
|
2012-07-10 19:47:33 -04:00
|
|
|
! Copyright (C) 2012 John Benediktsson
|
2012-09-11 13:33:47 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license
|
2012-07-10 19:47:33 -04:00
|
|
|
USING: accessors circular kernel math sequences sequences.private ;
|
2008-05-18 22:25:58 -04:00
|
|
|
IN: sequences.repeating
|
|
|
|
|
2012-08-09 18:07:45 -04:00
|
|
|
TUPLE: cycles
|
|
|
|
{ circular circular read-only }
|
|
|
|
{ length integer read-only } ;
|
2008-05-18 22:25:58 -04:00
|
|
|
|
2012-07-10 19:47:33 -04:00
|
|
|
: <cycles> ( seq length -- cycles )
|
|
|
|
[ <circular> ] dip cycles boa ;
|
2008-05-18 22:25:58 -04:00
|
|
|
|
2012-07-10 19:47:33 -04:00
|
|
|
: cycle ( seq length -- new-seq )
|
|
|
|
dupd <cycles> swap like ;
|
2008-05-18 22:25:58 -04:00
|
|
|
|
2012-07-10 19:47:33 -04:00
|
|
|
M: cycles length length>> ;
|
2012-08-09 18:07:45 -04:00
|
|
|
|
2012-07-10 19:47:33 -04:00
|
|
|
M: cycles set-length length<< ;
|
2008-05-18 22:25:58 -04:00
|
|
|
|
2018-02-16 11:31:22 -05:00
|
|
|
M: cycles virtual@ circular>> ;
|
2008-05-18 22:25:58 -04:00
|
|
|
|
2012-07-10 19:47:33 -04:00
|
|
|
M: cycles virtual-exemplar circular>> ;
|
2008-05-18 22:25:58 -04:00
|
|
|
|
2012-07-10 19:47:33 -04:00
|
|
|
INSTANCE: cycles virtual-sequence
|
|
|
|
|
2012-08-09 18:07:45 -04:00
|
|
|
TUPLE: repeats
|
|
|
|
{ seq sequence read-only }
|
2018-02-16 11:31:22 -05:00
|
|
|
{ times integer read-only } ;
|
2012-07-10 19:47:33 -04:00
|
|
|
|
2018-02-16 11:31:22 -05:00
|
|
|
C: <repeats> repeats
|
2012-07-10 19:47:33 -04:00
|
|
|
|
2018-02-16 11:31:22 -05:00
|
|
|
M: repeats length [ seq>> length ] [ times>> ] bi * ;
|
2012-07-10 19:47:33 -04:00
|
|
|
|
2018-02-16 11:31:22 -05:00
|
|
|
M: repeats virtual@ [ times>> /i ] [ seq>> ] bi ;
|
2012-07-10 19:47:33 -04:00
|
|
|
|
2018-02-16 11:31:22 -05:00
|
|
|
M: repeats virtual-exemplar seq>> ;
|
2012-07-10 19:47:33 -04:00
|
|
|
|
|
|
|
INSTANCE: repeats immutable-sequence
|
2018-02-16 11:31:22 -05:00
|
|
|
|
|
|
|
INSTANCE: repeats virtual-sequence
|
|
|
|
|
|
|
|
: repeat ( seq times -- new-seq )
|
|
|
|
dupd <repeats> swap like ;
|