Dear all,
while experimenting with the Set collection I am incurring in a very
strange behavior when I use a custom type. More precisely:
julia> type Test
x::Int
end
julia> import Base.==
julia> ==(a::Test, b::Test) = a.x == b.x
== (generic function with 110 methods)
julia>
https://github.com/JuliaLang/julia/issues/12198
On Fri, May 27, 2016 at 3:40 AM, Dario Prandi wrote:
> Dear all,
>
> while experimenting with the Set collection I am incurring in a very
> strange behavior when I use a custom type. More precisely:
>
> julia> type Test
>x::Int
>
I think you need to define hash for your type too as Set is based on
Dict. Read up here:
http://docs.julialang.org/en/release-0.4/stdlib/collections/?highlight=hash#associative-collections
On Fri, 2016-05-27 at 09:40, Dario Prandi wrote:
> Dear all,
>
> while experimenting with the Set collectio
That will fix your issue. The broader problem is that this is far too easy
to do without realizing what's wrong.
On Fri, May 27, 2016 at 8:18 AM, Mauro wrote:
> I think you need to define hash for your type too as Set is based on
> Dict. Read up here:
>
> http://docs.julialang.org/en/release-0.
Concretely:
julia> type Test
x::Int
end
julia> Base.hash(t::Test) = hash(t.x, hash(:Test))
julia> Base.:(==)(a::Test, b::Test) = a.x == b.x
julia> a = Set{Test}()
Set{Test}()
julia> push!(a, Test(1))
Set([Test(1)])
julia> push!(a, Test(1))
Set([Test(1)])
On Friday, M