sequences.rotated: can be a lot faster if we don't circular-wrap.
parent
1f2ecfde76
commit
5ea4e26bc5
|
@ -1,20 +1,24 @@
|
||||||
! Copyright (C) 2012 John Benediktsson
|
! Copyright (C) 2012 John Benediktsson
|
||||||
! See http://factorcode.org/license.txt for BSD license
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
USING: accessors circular kernel math sequences ;
|
USING: accessors kernel math sequences ;
|
||||||
IN: sequences.rotated
|
IN: sequences.rotated
|
||||||
|
|
||||||
TUPLE: rotated
|
TUPLE: rotated
|
||||||
{ circular circular read-only }
|
{ seq read-only }
|
||||||
{ n integer read-only } ;
|
{ n integer read-only } ;
|
||||||
|
|
||||||
: <rotated> ( seq n -- rotated )
|
C: <rotated> rotated
|
||||||
[ <circular> ] dip rotated boa ;
|
|
||||||
|
|
||||||
M: rotated length circular>> length ;
|
M: rotated length seq>> length ;
|
||||||
|
|
||||||
M: rotated virtual@ [ n>> + ] [ circular>> ] bi ;
|
M: rotated virtual@
|
||||||
|
[ n>> + ] [ seq>> ] bi [
|
||||||
|
length over 0 < [ + ] [
|
||||||
|
2dup >= [ - ] [ drop ] if
|
||||||
|
] if
|
||||||
|
] keep ;
|
||||||
|
|
||||||
M: rotated virtual-exemplar circular>> ;
|
M: rotated virtual-exemplar seq>> ;
|
||||||
|
|
||||||
INSTANCE: rotated virtual-sequence
|
INSTANCE: rotated virtual-sequence
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue