Skip to content

Commit

Permalink
fix iddicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Isensee committed Oct 26, 2023
1 parent d63e102 commit 23af351
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/data/specialcased_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,14 @@ writeas(::Type{Core.SimpleVector}) = Vector{Any}
wconvert(::Type{Vector{Any}}, x::Core.SimpleVector) = collect(Any, x)
rconvert(::Type{Core.SimpleVector}, x::Vector{Any}) = Core.svec(x...)

## Dicts

## Standard Dictionary Types
# Custom dictionaries may need to store additional fields
writeas(::Type{Dict{K,V}}) where {K,V} = Vector{Pair{K,V}}
writeas(::Type{IdDict{Any,Any}}) = Vector{Pair{Any,Any}}
writeas(::Type{IdDict{K,V}}) where {K,V} = Vector{Pair{K,V}}
writeas(::Type{Base.ImmutableDict{K,V}}) where {K,V} = Vector{Pair{K,V}}

wconvert(::Type{Vector{Pair{K,V}}}, x::AbstractDict{K,V}) where {K,V} = collect(x)
function rconvert(::Type{T}, x::Vector{Pair{K,V}}) where {T<:AbstractDict,K,V}
d = T()
isa(d, Dict) && sizehint!(d::Dict, length(x))
for (k,v) in x
d[k] = v
end
d
end
rconvert(::Type{T}, x::Vector{Pair{K,V}}) where {T<:Union{Dict,IdDict},K,V} = T(x)

function rconvert(::Type{<:Base.ImmutableDict}, x::Vector{Pair{K,V}}) where {K,V}
@assert !isempty(x)
Expand Down

0 comments on commit 23af351

Please sign in to comment.