Charles Turner wrote:
> Hi all-
> 
> I want to "interleave" two arrays in a different sense than the Factor  
> word of the same name:
> 
> { 1 2 3 } and { 3 2 1 } "interleaved" -> { 1 3 2 2 3 1 }
> 
> I've come up with this:
> 
> { 1 2 3 } { 3 2 1 } [ 2array ] 2map concat
> 
> but is there a more elegant/efficient/idiomatic way of doing what I  
> want?
> 

I tried:
{ 1 2 3 } { 3 2 1 } [ [ swap , , ] 2each ] { } make

to remove the extra array creation and the concat pass. AFAICS it's 
quicker on large arrays:

: testmake ( -- )
   100000 >array dup reverse
   [ [ swap , , ] 2each ] { } make drop ;

: testconcat ( -- )
   100000 >array dup reverse
   [ 2array ] 2map concat drop ;

( scratchpad ) [ testconcat ] gc benchmark [ testmake ] gc benchmark

--- Data stack:
129426
66924

(this with cpu pegged at 800mhz)

Cheers,

Phil


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to