boyer-moore: fixed indentation, typos

db4
Dmitry Shubin 2010-04-16 04:44:37 +04:00
parent 38ef5919e8
commit 87dfd458a5
3 changed files with 14 additions and 11 deletions

View File

@ -1,11 +1,11 @@
! Copyright (C) 2010 Dmitry Shubin. ! Copyright (C) 2010 Dmitry Shubin.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel sequences ; USING: boyer-moore.private help.markup help.syntax kernel sequences ;
IN: boyer-moore IN: boyer-moore
HELP: <boyer-moore> HELP: <boyer-moore>
{ $values { $values
{ "pat" sequence } { "bm" object } { "pat" sequence } { "bm" boyer-moore }
} }
{ $description { $description
"Given a pattern performs pattern preprocessing and returns " "Given a pattern performs pattern preprocessing and returns "
@ -43,7 +43,7 @@ ARTICLE: "boyer-moore" "The Boyer-Moore algorithm"
{ $heading "Summary" } { $heading "Summary" }
"The " { $vocab-link "boyer-moore" } " vocabulary " "The " { $vocab-link "boyer-moore" } " vocabulary "
"implements a Boyer-Moore string search algorithm with " "implements a Boyer-Moore string search algorithm with "
"so-called 'strong good suffix shift rule'. Since agorithm is " "so-called 'strong good suffix shift rule'. Since algorithm is "
"alphabet-independent it is applicable to searching in any " "alphabet-independent it is applicable to searching in any "
"collection that implements " { $links "sequence-protocol" } "." "collection that implements " { $links "sequence-protocol" } "."
@ -51,8 +51,8 @@ ARTICLE: "boyer-moore" "The Boyer-Moore algorithm"
"Let " { $snippet "n" } " and " { $snippet "m" } " be lengths " "Let " { $snippet "n" } " and " { $snippet "m" } " be lengths "
"of the sequences being searched " { $emphasis "in" } " and " "of the sequences being searched " { $emphasis "in" } " and "
{ $emphasis "for" } " respectively. Then searching runs in " { $emphasis "for" } " respectively. Then searching runs in "
{ $snippet "O(n)" } " time in it's worst case using additional " { $snippet "O(n)" } " time in its worst case using additional "
{ $snippet "O(m)" } " space. Preprocessing phase runs in " { $snippet "O(m)" } " space. The preprocessing phase runs in "
{ $snippet "O(m)" } " time." { $snippet "O(m)" } " time."
; ;

View File

@ -53,10 +53,12 @@ TUPLE: boyer-moore pattern bc-table gs-table ;
pat length :> plen pat length :> plen
seq length plen - :> lim seq length plen - :> lim
from from
[ dup lim <= [
[ seq pat pick plen mismatch? dup lim <=
[ 2dup + seq nth-unsafe bm do-shift t ] [ f ] if* [
] [ drop f f ] if seq pat pick plen mismatch?
[ 2dup + seq nth-unsafe bm do-shift t ] [ f ] if*
] [ drop f f ] if
] loop ; inline ] loop ; inline
PRIVATE> PRIVATE>

View File

@ -19,8 +19,9 @@ IN: z-algorithm
r k - 1 + :> b r k - 1 + :> b
seq Z Zk' b < seq Z Zk' b <
[ Zk' Z push l r ] ! still inside [ Zk' Z push l r ] ! still inside
[ seq r 1 + seq b [ tail-slice ] 2bi@ lcp :> q [
q b + Z push k q r + seq r 1 + seq b [ tail-slice ] 2bi@ lcp :> q
q b + Z push k q r +
] if ; inline ] if ; inline
: (z-value) ( seq Z l r k -- seq Z l r ) : (z-value) ( seq Z l r k -- seq Z l r )