I found this stackoverflow 
question: 
http://stackoverflow.com/questions/25678112/insert-item-into-a-sorted-list-with-julia-with-and-without-duplicates

with a great solution by Stefan.

Moving from [x] to x (see his followup) reduced the time to do this 
insert/dedup by ~30%.

Is there a more efficient way to do this? Here's the code I have right now:

function _insert_and_dedup!(v::Vector{Int}, x::Int)
    oldv = length(v)
    splice!(v, searchsorted(v,x), x)
    return (length(v) == oldv+1)
end

I'm returning true if the value was added; false if it was a duplicate 
(needed for some other function).

Reply via email to