]> gitweb.factorcode.org Git - factor.git/commitdiff
Move monotonic-split to splitting.monotonic
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 18 Dec 2008 02:04:41 +0000 (20:04 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 18 Dec 2008 02:04:41 +0000 (20:04 -0600)
basis/splitting/monotonic/authors.txt [new file with mode: 0644]
basis/splitting/monotonic/monotonic-tests.factor [new file with mode: 0644]
basis/splitting/monotonic/monotonic.factor [new file with mode: 0644]
basis/splitting/monotonic/summary.txt [new file with mode: 0644]
basis/splitting/monotonic/tags.txt [new file with mode: 0644]

diff --git a/basis/splitting/monotonic/authors.txt b/basis/splitting/monotonic/authors.txt
new file mode 100644 (file)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/basis/splitting/monotonic/monotonic-tests.factor b/basis/splitting/monotonic/monotonic-tests.factor
new file mode 100644 (file)
index 0000000..ab4c48b
--- /dev/null
@@ -0,0 +1,8 @@
+IN: splitting.monotonic
+USING: tools.test math arrays kernel sequences ;
+
+[ { { 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
+
diff --git a/basis/splitting/monotonic/monotonic.factor b/basis/splitting/monotonic/monotonic.factor
new file mode 100644 (file)
index 0000000..5bc7a51
--- /dev/null
@@ -0,0 +1,17 @@
+! Copyright (C) 2008 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: make namespaces sequences kernel fry ;
+IN: splitting.monotonic
+
+: ,, ( obj -- ) building get peek push ;
+: v, ( -- ) V{ } clone , ;
+: ,v ( -- ) building get dup peek empty? [ dup pop* ] when drop ;
+
+: (monotonic-split) ( seq quot -- newseq )
+    [
+        [ dup unclip suffix ] dip
+        v, '[ over ,, @ [ v, ] unless ] 2each ,v
+    ] { } make ; inline
+
+: monotonic-split ( seq quot -- newseq )
+    over empty? [ 2drop { } ] [ (monotonic-split) ] if ; inline
diff --git a/basis/splitting/monotonic/summary.txt b/basis/splitting/monotonic/summary.txt
new file mode 100644 (file)
index 0000000..6782bd0
--- /dev/null
@@ -0,0 +1 @@
+Split a sequence into monotonically-increasing subsequences
diff --git a/basis/splitting/monotonic/tags.txt b/basis/splitting/monotonic/tags.txt
new file mode 100644 (file)
index 0000000..d4c0877
--- /dev/null
@@ -0,0 +1,2 @@
+algorithms
+sequences