julia> type Foox::Intendjulia> import Base: ==julia> ==(f1::Foo, f2::Foo) = f1.x == f2.x== (generic function with 85 methods)julia> unique(foos)2-element Array{Foo,1}:Foo(4)Foo(4)julia> unique(foos)[1] == unique(foos)[2]true
julia> type Foox::Intendjulia> import Base: ==julia> ==(f1::Foo, f2::Foo) = f1.x == f2.x== (generic function with 85 methods)
julia> foos = [Foo(4), Foo(4)]
2-element Array{Foo,1}:Foo(4)Foo(4)julia> unique(foos)2-element Array{Foo,1}:Foo(4)Foo(4)julia> unique(foos)[1] == unique(foos)[2]true
julia> unique(foos)
1-element Array{Foo,1}:
Foo(4)$ julia -qjulia> versioninfo()Julia Version 0.4.0-dev+5860Commit 7fa43ed (2015-07-08 20:57 UTC)Platform Info: System: Darwin (x86_64-apple-darwin14.3.0) CPU: Intel(R) Core(TM) i5 CPU M 520 @ 2.40GHz WORD_SIZE: 64 BLAS: libopenblas (USE64BITINT NO_AFFINITY NEHALEM) LAPACK: libopenblas LIBM: libopenlibm LLVM: libLLVM-3.3
julia> type Foo x::Int end
julia> ==(f1::Foo, f2::Foo) = f1.x == f2.x== (generic function with 109 methods)
julia> unique([Foo(4),Foo(4)])2-element Array{Foo,1}: Foo(4) Foo(4)
julia> @which hash(Foo(4), zero(UInt))hash(x::ANY, h::UInt64) at hashing.jl:10julia> versioninfo()Julia Version 0.4.0-dev+5587Commit 78760e2 (2015-06-25 14:27 UTC)Platform Info:
System: Darwin (x86_64-apple-darwin14.3.0)CPU: Intel(R) Core(TM) M-5Y71 CPU @ 1.20GHzWORD_SIZE: 64BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Prescott)
LAPACK: libopenblasLIBM: libopenlibmLLVM: libLLVM-3.3julia> type Foox::Intend
julia> ==(f1::Foo, f2::Foo) = f1.x == f2.x== (generic function with 108 methods)julia> foos = [Foo(4), Foo(4)]2-element Array{Foo,1}:Foo(4)Foo(4)julia> unique(foos)
2-element Array{Foo,1}:Foo(4)Foo(4)
function unique(C)out = Array(eltype(C),0)seen = Set{eltype(C)}()for x in Cif !in(x, seen)push!(seen, x)push!(out, x)endendoutend
julia> unique([Foo(4),Foo(4)])2-element Array{Foo,1}: Foo(4) Foo(4)
julia> unique([Foo(4),Foo(4)])1-element Array{Foo,1}: Foo(4)
julia> unique([Foo(4),Foo(4)])2-element Array{Foo,1}: Foo(4) Foo(4)Stefan,If I'm reading between the lines correctly, the default/existing hash function is based on the last byte of the ID? Is there a reason we don't make the table wider to reduce the chances of collisions (or would this have bad effects on memory utilization)?
Also, back to the OP question, is the correct solution to simply defineBase.hash(f::Foo) = f.x
If I'm reading between the lines correctly, the default/existing hash function is based on the last byte of the ID? Is there a reason we don't make the table wider to reduce the chances of collisions (or would this have bad effects on memory utilization)?