I have an array of tuples, i.e. Array{Tuple{Int64, Int64}} which I would like to filter by unique items. That is, my uniqueness criteria for a tuple is that (x_1, x_2) = (x_2, x_1).
So if I have a = [(1, 2), (3, 4), (2, 1)] I basically want a return value of ret = [(1, 2), (3,4)](or equivalently [(3, 4), (2, 1)].
My current solution is simple, but costly in terms for performance. Solution is
JuMP defines an UnorderedPair; could copy that code, turn your tuples into UnorderedPairs, and use unique/unique!/isunique as usual. I think this should be in Base actually.
Do you need the original order for anything? If not, it may make sense to just sanitize the input. Eg
struct OrderedPair{T}
a::T
b::T
function OrderedPair(a::T, b::T) where T
if !isless(a, b)
b, a = a, b
end
new{T}(a, b)
end
end
OrderedPair(ab::Tuple{T,T}) where {T} = OrderedPair(ab...)