Well, doing a linear search, when inserting n items, isn't that going to be 
O(n^2)?
I would hope that using a dictionary would give me something more like O(n 
log n)...

On Tuesday, May 19, 2015 at 9:30:48 AM UTC-4, David Gold wrote:
>
> Perhaps I'm being naive, but is there anything wrong with findfirst? 
> http://docs.julialang.org/en/release-0.3/stdlib/arrays/#Base.findfirst
>
> function findoradd(A::Array{Int64, 1}, value::Int64)
>     if findfirst(A, value) > 0
>         return findfirst(A, value)
>     else
>         push!(A, value)
>         return length(A)
>     end
> end
>
>
> Though I don't know how well the above would work for arrays of bytes, or 
> how it performs compared to a dictionary. 
>
> On Monday, May 18, 2015 at 4:46:28 PM UTC-4, Scott Jones wrote:
>>
>> I would like to be able to do the following in Julia:
>> Take a UInt64 (or UInt128, for that matter), and add it to an array, if 
>> it is not already present, returning the index.
>> (This would be trivial in the language I used to work on, and I think it 
>> probably is in Julia as well, but I haven't found the right data structure 
>> yet...)
>> What would be the best performing way of handling that?
>> What if, instead of an UInt64 or UInt128, I had an array of bytes (like 
>> 128 or 256)?  What would be the best way for that?
>>
>> Thanks, Scott
>>
>

Reply via email to