, , , , . , - , , . , - , . , MyT , :
immutable MyT
A::String
B::Int64
end
dic = Dict{MyT, Int64}()
for i in 1:10
dic[MyT("x", 1)] = 1
end
julia> dic
Dict{MyT,Int64} with 1 entry:
MyT("x", 1) => 1
julia> keys(dic)
Base.KeyIterator for a Dict{MyT,Int64} with 1 entry. Keys:
MyT("x", 1)
, String Int, -, , , . , , , , 0,6 struct mutable struct - , , , - .
@ntdef, , Base.hash. , (, , , ):
Base.hash, , Base.hash(::T, ::UInt).Base.hash(::T, ::UInt) UInt.Base.hash, Base.== .
, ( Julia MyT):
type MyT
A::String
B::Int64
end
import Base: ==, hash
==(x::MyT, y::MyT) = x.A == y.A && x.B == y.B
hash(x::MyT, h::UInt) = hash((MyT, x.A, x.B), h)
dic = Dict{MyT, Int64}()
for i in 1:10
dic[MyT("x", 1)] = 1
end
julia> dic
Dict{MyT,Int64} with 1 entry:
MyT("x", 1) => 1
julia> keys(dic)
Base.KeyIterator for a Dict{MyT,Int64} with 1 entry. Keys:
MyT("x", 1)
, AutoHashEquals , . , , type @auto_hash_equals:
using AutoHashEquals
@auto_hash_equals type MyT
A::String
B::Int64
end
:
, , , .
, , -.
- , AutoHashEquals.