Hi, I was wondering, could anyone help me with clarifying a little bit of a line of the following code?
######################################
### Find Intersections of Highways ###
######################################
function find_intersections(highways::Vector{OpenStreetMapX.Way})
seen = Set{Int}()
intersections = Dict{Int,Set{Int}}()
for highway in highways
for i = 1:length(highway.nodes)
if i == 1 || i == length(highway.nodes) || (highway.nodes[i] in seen)
get!(Set{Int}, intersections, highway.nodes[i])
else
push!(seen, highway.nodes[i])
end
end
end
for highway in highways
for i = 1:length(highway.nodes)
if i == 1 || i == length(highway.nodes) || haskey(intersections, highway.nodes[i])
push!(intersections[highway.nodes[i]], highway.id)
end
end
end
return intersections
end
I’m mainly confused with the code get!(Set{Int}, intersections, highway.nodes[i])
. From my understanding, the first for loop will have the keys of the dictionary ready and the second for loop will have the values of the dictionary ready. However, I’m not exactly sure what is done with the above line of code. Any comments are greatly appreciated.