diff --git a/basis/lcs/lcs.factor b/basis/lcs/lcs.factor index 5861d90dc3..08ab044ba0 100644 --- a/basis/lcs/lcs.factor +++ b/basis/lcs/lcs.factor @@ -1,22 +1,22 @@ -USING: sequences kernel math locals math.order math.ranges -accessors arrays namespaces make combinators -combinators.short-circuit ; +USING: accessors arrays combinators combinators.short-circuit +kernel locals make math math.order sequences sequences.private ; IN: lcs ] with map ; @@ -27,9 +27,11 @@ IN: lcs :: run-lcs ( old new init step -- matrix ) old length 1 + new length 1 + init call :> matrix old length iota [| i | - new length iota - [| j | i j matrix old new step loop-step ] each + new length iota [| j | + i j matrix old new step loop-step + ] each ] each matrix ; inline + PRIVATE> : levenshtein ( old new -- n ) @@ -41,17 +43,18 @@ TUPLE: delete item ; TUPLE: insert item ; > 1 - ] [ old>> ] bi nth ; + [ i>> 1 - ] [ old>> ] bi nth-unsafe ; : new-nth ( state -- elt ) - [ j>> 1 - ] [ new>> ] bi nth ; + [ j>> 1 - ] [ new>> ] bi nth-unsafe ; : top-beats-side? ( state -- ? ) - [ [ i>> ] [ j>> 1 - ] [ table>> ] tri nth nth ] - [ [ i>> 1 - ] [ j>> ] [ table>> ] tri nth nth ] bi > ; + [ [ i>> ] [ j>> 1 - ] [ table>> ] tri nth-unsafe nth-unsafe ] + [ [ i>> 1 - ] [ j>> ] [ table>> ] tri nth-unsafe nth-unsafe ] bi > ; : retained? ( state -- ? ) { @@ -91,7 +94,8 @@ TUPLE: trace-state old new table i j ; : trace-diff ( old new table -- diff ) [ ] [ first length 1 - ] [ length 1 - ] tri trace-state boa - [ (trace-diff) ] { } make reverse ; + [ (trace-diff) ] { } make reverse! ; + PRIVATE> : diff ( old new -- diff )