I’m confused I have this piece of code (see below, the important part is the the push! … line), it will push a value to a set located in a dict at a key (called “coord”) that we have already verified exists in the dict using a “coord in dict.keys
” test. Mostly this code runs well, but from time to time, it fails with an error message like **ERROR:** KeyError: key (487, 466) not found"
(the actual numbers vary between the tests).
I’m very confused by this. Also I’m not very experienced with Julia, so there may easily be stupid things I’ve done :-).
The full source code can be found here: https://github.com/la3lma/julia-playground/blob/master/ParticleMovement.jl
To reproduce the error, run “runSmoketest(10)” after loading the module.
function partition(particles::Set{ParticleState}, xdim::Int64, ydim::Int64, maxx::Float64, maxy::Float64)
dict = Dict{Tuple{Int64, Int64}, Set{ParticleState}}()
for p in particles
coord = pointToImageCoord(p.pos, xdim, ydim, maxx, maxy)
if (coord in dict.keys)
push!(dict[coord], p)
else
newSet = Set{ParticleState}([p])
dict[coord] = newSet
end
end
return dict
end