Hi,
I found some unexpected behavour when checking set membership.
Specifically, I get a key error when I try to pop! a known member of a set.
The problem does not occur in a pattern that I could predict, but I prepared a script that reproduces it consistently in my environment.
This is probably a bug, but I would like to know whether this is a known issue and whether I should log it.
-
versioninfo():
Julia Version 1.9.4
Commit 8e5136fa29 (2023-11-14 08:46 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 8 Γ Intel(R) Coreβ’ i7-4790 CPU @ 3.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, haswell)
Threads: 8 on 8 virtual cores
Environment:
JULIA_NUM_THREADS = 8
JULIA_EDITOR = code -
Julia was installed using the windows installer.
-
Code and error message:
int_vec = [[9, 8, 2, 9, 3, 4, 1, 4, 6],
[2, 5],
[1, 4, 9, 8, 2, 3, 6, 3, 7],
[3, 2, 10, 9, 9, 3, 2, 1, 2, 5],
[8, 6, 1],
[7, 3, 10, 7, 8, 5, 3, 10],
[5, 6, 6, 8],
[3],
[6, 10, 2, 2, 7],
[2, 2, 7],
[7, 1],
[7],
[10, 6, 3, 1, 1, 2, 1],
[5, 6, 2, 10, 4, 1],
[6, 7],
[5, 8],
[5, 7, 7, 5],
[6, 6, 9, 6, 9, 1, 1, 5],
[2, 5, 10, 10]]
function check_length(subset,element)
return length(subset) == length(element)
end
function test(input_vector)
input_set = Set(input_vector)
s = Set()
push!(s,Set((pop!(input_set),)))
while !isempty(input_set)
new_element = pop!(input_set)
ss = Set(x for x in s if check_length(x,new_element))
if isempty(ss)
push!(s, Set((new_element,)))
elseif length(ss) == 1
myst = pop!(ss)
push!(myst,new_element)
else
for x in ss
_ = pop!(s,x)
end
su = reduce(union, ss)
push!(su,new_element)
push!(s,su)
end
end
return s
end
The error eventually occurs in line 39:
_ = pop!(s,x)
If I use setdiff, or setdiff! here, it also fails to remove the element.
The error message is:
ERROR: KeyError: key Set([[1, 4, 9, 8, 2, 3, 6, 3, 7], [10, 6, 3, 1, 1, 2, 1], [3], [8, 6, 1], [5, 7, 7, 5]]) not found
Stacktrace:
[1] pop!(h::Dict{Any, Nothing}, key::Set{Vector{Int64}})
@ Base .\dict.jl:590
[2] pop!(s::Set{Any}, x::Set{Vector{Int64}})
@ Base .\set.jl:104
[3] test(input_vector::Vector{Vector{Int64}})
@ Main c:\Users\Use\OneDrive\Development\Julia\Projects\AoC2023\test.jl:39
[4] top-level scope
@ REPL[4]:1