mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-25 18:15:29 +01:00
add missing cases for find first (length =0, 1)
This commit is contained in:
parent
613ec172bd
commit
5a9d4b4bb6
@ -271,21 +271,32 @@ is_subsymbol(s::GSymbol, t::GSymbol) =
|
|||||||
function findfirst(W::GWord, Z::GWord)
|
function findfirst(W::GWord, Z::GWord)
|
||||||
n = length(Z.symbols)
|
n = length(Z.symbols)
|
||||||
|
|
||||||
@assert n > 1
|
if n == 0
|
||||||
for (idx,a) in enumerate(W.symbols)
|
return 0
|
||||||
if idx + n - 1 > length(W.symbols)
|
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
|
break
|
||||||
end
|
end
|
||||||
foundfirst = is_subsymbol(Z.symbols[1],a)
|
foundfirst = is_subsymbol(Z.symbols[1], a)
|
||||||
if foundfirst
|
if foundfirst
|
||||||
middlematch = W.symbols[idx+1:idx+n-2] == Z.symbols[2:end-1]
|
middlematch = W.symbols[idx+1:idx+n-2] == Z.symbols[2:end-1]
|
||||||
lastmatch = is_subsymbol(Z.symbols[end], W.symbols[idx+n-1])
|
lastmatch = is_subsymbol(Z.symbols[end], W.symbols[idx+n-1])
|
||||||
if middlematch && lastmatch
|
if middlematch && lastmatch
|
||||||
return idx
|
return idx
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return 0
|
end
|
||||||
|
|
||||||
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function findnext(W::GWord, Z::GWord, i::Integer)
|
function findnext(W::GWord, Z::GWord, i::Integer)
|
||||||
|
Loading…
Reference in New Issue
Block a user