using StrngViews
julia> function multisbsSV(str,sstr, s)
cstr,csstr,cs=codeunits.([str,sstr, s])
lcstr,lcsstr,lcs = length.([cstr,csstr,cs])
l=lcs-(lcstr-lcsstr)
fp=findfirst(cstr, cs)
tmp=Vector{UInt8}(undef,l)
res=Vector{StringView}(undef,lcs-lcsstr)
j=1
while !isnothing(fp)
fs,ls=first(fp),last(fp)
copyto!(tmp,1, cs,1,fs-1)
copyto!(tmp,fs,csstr)
copyto!(tmp,ls,cs,ls+1,lcs-ls)
res[j]=StringView(tmp)
j+=1
fp=findnext(cstr, cs,first(fp)+1)
end
@view res[1:j-1]
end
multisbs3 (generic function with 1 method)
julia> function multisbsSC(str,sstr, s)
cstr,csstr,cs=codeunits.([str,sstr, s])
lcstr,lcsstr,lcs = length.([cstr,csstr,cs])
l=lcs-(lcstr-lcsstr)
fp=findfirst(cstr, cs)
tmp=Vector{UInt8}(undef,l)
res=Vector{String}(undef,lcs-lcsstr)
j=1
while !isnothing(fp)
fs,ls=first(fp),last(fp)
copyto!(tmp,1, cs,1,fs-1)
copyto!(tmp,fs,csstr)
copyto!(tmp,ls,cs,ls+1,lcs-ls)
res[j]=String(copy(tmp))
j+=1
fp=findnext(cstr, cs,first(fp)+1)
end
@view res[1:j-1]
end
multisbs4 (generic function with 1 method)
julia> @btime multisbsSV("BB","A","BBBBBaBBCCDDDDDDDAA")
497.423 ns (11 allocations: 672 bytes)
5-element view(::Vector{StringView}, 1:5) with eltype StringView:
"BBBBBaACCDDDDDDDAA"
"BBBBBaACCDDDDDDDAA"
"BBBBBaACCDDDDDDDAA"
"BBBBBaACCDDDDDDDAA"
"BBBBBaACCDDDDDDDAA"
julia> @btime multisbsSC("BB","A","BBBBBaBBCCDDDDDDDAA")
637.126 ns (16 allocations: 1.16 KiB)
5-element view(::Vector{String}, 1:5) with eltype String:
"ABBBaBBCCDDDDDDDAA"
"BABBaBBCCDDDDDDDAA"
"BBABaBBCCDDDDDDDAA"
"BBBAaBBCCDDDDDDDAA"
"BBBBBaACCDDDDDDDAA"