sequences: faster "flip", looks at each element only once.

db4
John Benediktsson 2012-09-05 16:02:20 -07:00
parent c86b2d2161
commit 6f66173784
1 changed files with 8 additions and 2 deletions

View File

@ -1010,7 +1010,10 @@ M: object sum 0 [ + ] binary-reduce ; inline
<PRIVATE
: generic-flip ( matrix -- newmatrix )
[ dup first length [ length min ] reduce iota ] keep
[
[ first-unsafe length 1 ] keep
[ length min ] (each) (each-integer) iota
] keep
[ [ nth-unsafe ] with { } map-as ] curry { } map-as ; inline
USE: arrays
@ -1020,7 +1023,10 @@ USE: arrays
: array-flip ( matrix -- newmatrix )
{ array } declare
[ dup first array-length [ array-length min ] reduce iota ] keep
[
[ first-unsafe array-length 1 ] keep
[ array-length min ] (each) (each-integer) iota
] keep
[ [ { array } declare array-nth ] with { } map-as ] curry { } map-as ;
PRIVATE>