Sorry in advance for the long post.
I have some trouble with a bug in one of my program. I was able to reproduce it with a simpler code, and it seems to be related to the Dict
structure. I am not sure if the problem is coming from my code or from the structure itself in Base
.
FYI:
Julia Version 0.6.0
Commit 9036443 (2017-06-19 13:05 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Xeon(R) CPU E5-1603 v4 @ 2.80GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)
EDIT: Behaviour is similar on a windows computer, so it seems to not be related to my setup
The idea here is just to search for all the permutations possible of the elements of Dictionary d
. At some point, a problem occurs (cf the associated comment) and gives the value 0
to j
. This value is supposedly from the keys of d
, and should always be in 1:k
(when the function is called with arg value k
).
The error KeyError: key 0 not found
seems to be raised for k >= 8
function mytest_inner(d::Dict{Int, Int}, i::Int)
println(d)
println("i = $i")
pop!(d, i)
for j in keys(d) # Problem is coming from here
mytest_inner(deepcopy(d), j)
end
end
function mytest(k::Int)
for i in 1:k
d = Dict(enumerate(1:k))
mytest_inner(d, i)
end
end
mytest(8)
The (shortened) output that illustrate this follows:
...
Dict(7=>7,4=>4,2=>2,3=>3,5=>5,8=>8,6=>6,1=>1)
i = 1
Dict(7=>7,4=>4,2=>2,3=>3,5=>5,8=>8,6=>6)
i = 7
Dict(4=>4,2=>2,3=>3,5=>5,8=>8,6=>6)
i = 4
...
Dict(3=>3,5=>5,8=>8,6=>6)
i = 5
Dict(3=>3,8=>8,6=>6)
i = 3
Dict(8=>8,6=>6)
i = 8
Dict(6=>6)
i = 6
Dict(8=>8,6=>6)
i = 6
Dict(8=>8)
i = 8
Dict(3=>3,8=>8,6=>6)
i = 0
With the last value of i
, the call to d[i]
is indeed raising an error.
Any help?