JuliaCollections/OrderedCollections.jl

OrderedDict should rehash on deepcopy (like Dict does)

オープン

#115 opened on 2024/04/20

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)Julia (42 件のフォーク)auto 404
good first issue

Repository metrics

Stars
 (112 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

Compare:

julia> mutable struct ConstIdentity
       end

julia> dict = OrderedDict{ConstIdentity, Int64}()
Dict{ConstIdentity, Int64}()

julia> dict[ConstIdentity()] = 1
1

julia> dict[ConstIdentity()] = 2
2

julia> all(haskey.((dict,), keys(dict)))
true

julia> dict2 = deepcopy(dict)
OrderedDict{ConstIdentity, Int64} with 2 entries:
  ConstIdentity() => 1
  ConstIdentity() => 2

julia> all(haskey.((dict2,), keys(dict2)))
false

vs Dict:

julia> mutable struct ConstIdentity
       end

julia> dict = Dict{ConstIdentity, Int64}()
Dict{ConstIdentity, Int64}()

julia> dict[ConstIdentity()] = 1
1

julia> dict[ConstIdentity()] = 2
2

julia> all(haskey.((dict,), keys(dict)))
true

julia> dict2 = deepcopy(dict)
Dict{ConstIdentity, Int64} with 2 entries:
  ConstIdentity() => 1
  ConstIdentity() => 2

julia> all(haskey.((dict2,), keys(dict2)))
true

We need to override deepcopy_internal to rehash like base does: https://github.com/JuliaLang/julia/blob/13155226e11fa025be5d4d3033d25c1091b35887/base/deepcopy.jl#L141-L156

コントリビューターガイド