Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrderedDict should rehash on deepcopy (like Dict does) #115

Open
Keno opened this issue Apr 20, 2024 · 0 comments
Open

OrderedDict should rehash on deepcopy (like Dict does) #115

Keno opened this issue Apr 20, 2024 · 0 comments
Labels
good first issue Good for newcomers

Comments

@Keno
Copy link

Keno commented Apr 20, 2024

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

@Keno Keno changed the title OrderedDict just rehash on deepcopy (like Dict does) OrderedDict should rehash on deepcopy (like Dict does) Apr 20, 2024
@fingolfin fingolfin added the good first issue Good for newcomers label Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants