Refactor Edit length to use dispatch instead of type checking

This commit is contained in:
Thomas A. Christensen II 2022-12-30 14:54:03 -06:00
parent 22d460b15a
commit cab3029bc6

View file

@ -13,9 +13,10 @@ struct Edit{S<:BioSequence,T<:BioSymbol}
x::Union{Substitution{T},Deletion,Insertion{S}}
pos::UInt
end
Base.length(e::Edit) = length(mutation(e))
Base.:(==)(e1::Edit, e2::Edit) = e1.pos == e2.pos && e1.x == e2.x
Base.hash(x::Edit, h::UInt) = hash(Edit, hash((x.x, x.pos), h))
Base.length(e::Edit) = e isa Substitution ? 1 : length(mutation(e))
function Base.parse(::Type{T}, s::AbstractString) where {T<:Edit{Se,Sy}} where {Se,Sy}
return parse(T, String(s))