I managed to squeeze a bit more performance out of it: _insert_and_dedup!(v::Vector{Int}, x::Int) = isempty(splice!(v, searchsorted (v,x), x))
If there's a better way of doing it, please let me know. On Monday, November 16, 2015 at 3:37:34 PM UTC-8, Seth wrote: > > 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). > >