]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/lcs/lcs.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / basis / lcs / lcs.factor
index ab4fbd60bb9fdbdf2c7b2daa5ab7768f18b3a950..aabd4bbafcd6e84d55d4dbb7e008e197b30ecf0d 100644 (file)
@@ -5,18 +5,18 @@ IN: lcs
 \r
 <PRIVATE\r
 : levenshtein-step ( insert delete change same? -- next )\r
-    0 1 ? + [ [ 1+ ] bi@ ] dip min min ;\r
+    0 1 ? + [ [ 1 + ] bi@ ] dip min min ;\r
 \r
 : lcs-step ( insert delete change same? -- next )\r
     1 -1/0. ? + max max ; ! -1/0. is -inf (float)\r
 \r
 :: loop-step ( i j matrix old new step -- )\r
-    i j 1+ matrix nth nth ! insertion\r
-    i 1+ j matrix nth nth ! deletion\r
+    i j 1 + matrix nth nth ! insertion\r
+    i 1 + j matrix nth nth ! deletion\r
     i j matrix nth nth ! replace/retain\r
     i old nth j new nth = ! same?\r
     step call\r
-    i 1+ j 1+ matrix nth set-nth ; inline\r
+    i 1 + j 1 + matrix nth set-nth ; inline\r
 \r
 : lcs-initialize ( |str1| |str2| -- matrix )\r
     [ drop 0 <array> ] with map ;\r
@@ -25,7 +25,7 @@ IN: lcs
     [ [ + ] curry map ] with map ;\r
 \r
 :: run-lcs ( old new init step -- matrix )\r
-    [let | matrix [ old length 1+ new length 1+ init call ] |\r
+    [let | matrix [ old length 1 + new length 1 + init call ] |\r
         old length [| i |\r
             new length\r
             [| j | i j matrix old new step loop-step ] each\r
@@ -44,14 +44,14 @@ TUPLE: insert item ;
 TUPLE: trace-state old new table i j ;\r
 \r
 : old-nth ( state -- elt )\r
-    [ i>> 1- ] [ old>> ] bi nth ;\r
+    [ i>> 1 - ] [ old>> ] bi nth ;\r
 \r
 : new-nth ( state -- elt )\r
-    [ j>> 1- ] [ new>> ] bi nth ;\r
+    [ j>> 1 - ] [ new>> ] bi nth ;\r
 \r
 : top-beats-side? ( state -- ? )\r
-    [ [ i>> ] [ j>> 1- ] [ table>> ] tri nth nth ]\r
-    [ [ i>> 1- ] [ j>> ] [ table>> ] tri nth nth ] bi > ;\r
+    [ [ i>> ] [ j>> 1 - ] [ table>> ] tri nth nth ]\r
+    [ [ i>> 1 - ] [ j>> ] [ table>> ] tri nth nth ] bi > ;\r
 \r
 : retained? ( state -- ? )\r
     {\r
@@ -61,7 +61,7 @@ TUPLE: trace-state old new table i j ;
 \r
 : do-retain ( state -- state )\r
     dup old-nth retain boa ,\r
-    [ 1- ] change-i [ 1- ] change-j ;\r
+    [ 1 - ] change-i [ 1 - ] change-j ;\r
 \r
 : inserted? ( state -- ? )\r
     {\r
@@ -70,7 +70,7 @@ TUPLE: trace-state old new table i j ;
     } 1&& ;\r
 \r
 : do-insert ( state -- state )\r
-    dup new-nth insert boa , [ 1- ] change-j ;\r
+    dup new-nth insert boa , [ 1 - ] change-j ;\r
 \r
 : deleted? ( state -- ? )\r
     {\r
@@ -79,7 +79,7 @@ TUPLE: trace-state old new table i j ;
     } 1&& ;\r
 \r
 : do-delete ( state -- state )\r
-    dup old-nth delete boa , [ 1- ] change-i ;\r
+    dup old-nth delete boa , [ 1 - ] change-i ;\r
 \r
 : (trace-diff) ( state -- )\r
     {\r
@@ -90,7 +90,7 @@ TUPLE: trace-state old new table i j ;
     } cond ;\r
 \r
 : trace-diff ( old new table -- diff )\r
-    [ ] [ first length 1- ] [ length 1- ] tri trace-state boa\r
+    [ ] [ first length 1 - ] [ length 1 - ] tri trace-state boa\r
     [ (trace-diff) ] { } make reverse ;\r
 PRIVATE>\r
 \r