The following is the code, excerpted from OpenStreetMapX package. I do not quite understand what is the purpose of the hash function here? Based on the help of the hash function from REPL, the hash function hash(x[, h::UInt])
is used to compute an integer hash code such that isequal(x,y)
implies hash(x) == hash(y)
. The optional second argument h is a hash code to be mixed with the result.
function add_new_node!(nodes::Dict{Int,T},loc::T, start_id::Int = reinterpret((Int), hash(loc))) where T <: (Union{OpenStreetMapX.LLA,OpenStreetMapX.ENU})
id = start_id
while id <= typemax(Int)
if !haskey(nodes, id)
nodes[id] = loc
return id
end
id += 1
end
msg = "Unable to add new node to map, $(typemax(Int)) nodes is the current limit."
throw(error(msg))
end