1
0
mirror of https://github.com/kalmarek/Groups.jl.git synced 2024-12-25 02:05:30 +01:00

add missing cases for find first (length =0, 1)

This commit is contained in:
kalmar 2017-07-05 16:16:47 +02:00
parent 613ec172bd
commit 5a9d4b4bb6

View File

@ -271,12 +271,21 @@ is_subsymbol(s::GSymbol, t::GSymbol) =
function findfirst(W::GWord, Z::GWord)
n = length(Z.symbols)
@assert n > 1
if n == 0
return 0
elseif n == 1
for (i,s) in enumerate(W.symbols)
if is_subsymbol(Z.symbols[1], s)
return i
end
end
return 0
else
for (idx,a) in enumerate(W.symbols)
if idx + n - 1 > length(W.symbols)
break
end
foundfirst = is_subsymbol(Z.symbols[1],a)
foundfirst = is_subsymbol(Z.symbols[1], a)
if foundfirst
middlematch = W.symbols[idx+1:idx+n-2] == Z.symbols[2:end-1]
lastmatch = is_subsymbol(Z.symbols[end], W.symbols[idx+n-1])
@ -285,6 +294,8 @@ function findfirst(W::GWord, Z::GWord)
end
end
end
end
return 0
end