Knuth-Morris-Pratt string search: Difference between revisions
m
→{{header|Raku}}: insignificant changes
(added Raku programming solution) |
m (→{{header|Raku}}: insignificant changes) |
||
Line 391:
<lang perl6># 20220810 Raku programming solution
sub kmp_search (@S where *.Bool, @W where *.Bool) {
sub kmp_table (@W where *.Bool) {
loop (my ($pos,$cnd,@T) = 1,0,-1 ; $pos < @W.elems ; ($pos, $cnd)>>
if @W[$pos] eq @W[$cnd] {
@T[$pos] = @T[$cnd]
Line 406:
}
return gather loop (my ($j,$k,@T) = 0,0, |kmp_table @W; $j < @S.elems; ) {
if @W[$k] eq @S[$j] {
($j, $k)>>
if $k == @W.elems {
take $j - $k;
Line 416 ⟶ 414:
}
} else {
($j, $k)>>
}
}
|