On Thursday, June 2, 2016 at 11:42:32 PM UTC-4, [email protected] wrote:
>
> function Base.filter!{T}(x::AbstractVector{T}, r::BasicInterval{T})
> for n = length(x):-1:1
> !in(x[n], r) && deleteat!(x, n)
> end
> return(x)
> end
>
I'm pretty sure this implementation has O(n^2) complexity, because
deleteat! for an array has to actually move all of the elements to fill the
hole.
To get an O(n) algorithm, you could do something like:
j = 0
for i = 1:length(x)
if x[i] in r
x[j += 1] = x[i]
end
end
return resize!(x, j)
Or you could just do filter!(x -> x in r, x), which is fast in Julia 0.5