Defining a specific dictionary key

If you are specifically using 2-element tuples of integers, a high-performance solution is to use the minmax function as follows:

julia> A = Dict{Tuple{Int, Int}, Float64}();

julia> A[1,2] = 7.0;

julia> A[minmax(1,2)...], A[minmax(2,1)...]
(7.0, 7.0)

If you’d like to extend to longer tuples and/or unordered elements, I don’t know an allocation-free option. Sets are a good suggestion by @hendri54 .

2 Likes