]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences.windowed: faster rolling-map.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 12 Oct 2013 18:43:46 +0000 (11:43 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 12 Oct 2013 18:43:46 +0000 (11:43 -0700)
basis/sequences/windowed/windowed.factor

index 844c65a7e88b293fdd1a0d7b1b46c91e74d16fbe..1cea80f01f9c790d7c87d622f4a14ab1e165d6ab 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2012 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors fry kernel math math.order math.statistics
-sequences sequences.private ;
+USING: accessors fry kernel locals math math.order
+math.statistics sequences sequences.private ;
 IN: sequences.windowed
 
 TUPLE: windowed-sequence
@@ -24,8 +24,10 @@ M: windowed-sequence length
 : in-bounds ( a b sequence -- a' b' sequence )
     [ nip in-bound ] [ [ nip ] dip in-bound ] [ 2nip ] 3tri ;
 
-: rolling-map ( seq n quot: ( slice -- elt ) -- newseq )
-    [ <windowed-sequence> ] [ map ] bi* ; inline
+:: rolling-map ( seq n quot: ( slice -- elt ) -- newseq )
+    seq length [
+        [ n [-] ] [ seq <slice-unsafe> ] bi quot call
+    ] { } map-integers ; inline
 
 : rolling-sum ( seq n -- newseq )
     [ sum ] rolling-map ;