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 <dario....@gmail.com> 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
>    end
>
> julia> import Base.==
>
> julia> ==(a::Test, b::Test) = a.x == b.x
> == (generic function with 110 methods)
>
> julia> a = Set{Test}()
> Set{Test}()
>
> julia> push!(a, Test(1))
> Set([Test(1)])
>
> julia> push!(a, Test(1))
> Set([Test(1),Test(1)])
>
> This should not happen, since Test(1)==Test(1). Moreover, I get the following
>
> julia> Test(1) ∈ a
> true
>
> julia> haskey(a.dict, Test(1))
> false
>
> which is quite strange, since the definition of the∈ function is
>
> in(x, s::Set) = haskey(s.dict, x)
>
> Finally, I remark that the following works correctly
>
> julia> x = Test(1)
> Test(1)
>
> julia> a = Set{Test}()
> Set{Test}()
>
> julia> push!(a,x)
> Set([Test(1)])
>
> julia> push!(a,x)
> Set([Test(1)])
>
> Someone has any idea of what is happening here? I'm on v0.4.5, butthe same
> behavior is reproducible onv0.5.
>
> Thanks,
> Dario

Reply via email to