]> gitweb.factorcode.org Git - factor.git/commitdiff
splitting.monotonic: faster monotonic-split.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 16 Nov 2014 00:52:31 +0000 (16:52 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 16 Nov 2014 00:52:31 +0000 (16:52 -0800)
basis/splitting/monotonic/monotonic-tests.factor
basis/splitting/monotonic/monotonic.factor

index 64d1ac0ee6d86887e82eb7d348a98f996c073d8e..4703f0273abf129c30c902a7234d4099025300ec 100644 (file)
@@ -2,10 +2,13 @@ IN: splitting.monotonic
 USING: tools.test math arrays kernel sequences ;
 
 { { } } [ { } [ < ] monotonic-split ] unit-test
-[ { { 1 } { -1 5 } { 2 4 } } ]
-[ { 1 -1 5 2 4 } [ < ] monotonic-split [ >array ] map ] unit-test
-[ { { 1 1 1 1 } { 2 2 } { 3 } { 4 } { 5 } { 6 6 6 } } ]
-[ { 1 1 1 1 2 2 3 4 5 6 6 6 } [ = ] monotonic-split [ >array ] map ] unit-test
+{ { V{ 1 } } } [ { 1 } [ < ] monotonic-split ] unit-test
+{ { V{ 1 2 } } } [ { 1 2 } [ < ] monotonic-split ] unit-test
+{ { V{ 1 } V{ 2 } } } [ { 1 2 } [ > ] monotonic-split ] unit-test
+[ { V{ 1 } V{ -1 5 } V{ 2 4 } } ]
+[ { 1 -1 5 2 4 } [ < ] monotonic-split ] unit-test
+[ { V{ 1 1 1 1 } V{ 2 2 } V{ 3 } V{ 4 } V{ 5 } V{ 6 6 6 } } ]
+[ { 1 1 1 1 2 2 3 4 5 6 6 6 } [ = ] monotonic-split ] unit-test
 
 [ { } ]
 [ { } [ = ] slice monotonic-slice ] unit-test
index 2e37b1d2794bca8c4c01468b88288c86fe804145..6c7f3463a59fea57d83b360f05702d6dfed2f1a6 100644 (file)
@@ -7,15 +7,11 @@ IN: splitting.monotonic
 
 <PRIVATE
 
-: ,, ( obj -- ) building get last push ;
-: v, ( -- ) V{ } clone , ;
-: ,v ( -- ) building get dup last empty? [ dup pop* ] when drop ;
-
 : (monotonic-split) ( seq quot -- newseq )
-    [
-        [ dup unclip suffix ] dip
-        v, '[ over ,, @ [ v, ] unless ] 2each ,v
-    ] { } make ; inline
+    [ V{ } clone V{ } clone ] 2dip [ ] swap '[
+        [ [ over push ] keep ] dip
+        [ @ [ over push V{ } clone ] unless ] keep
+    ] map-reduce over push over push { } like ; inline
 
 PRIVATE>