Skip to content

Commit 5ec1764

Browse files
authored
LittleDict constructor from AbstractDict (#150)
Formerly, statements like `convert(typeof(ld), d)` would fail if `ld` was a `LittleDict` and `d` was an `AbstractDict`.
1 parent 7b3daef commit 5ec1764

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "OrderedCollections"
22
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
3-
version = "1.8.0"
3+
version = "1.8.1"
44

55
[compat]
66
julia = "1.7.1"

src/little_dict.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct LittleDict{K, V, KS<:StoreType{K}, VS<:StoreType{V}} <: AbstractDict{K, V
4545
LittleDict{K, V, <:Tuple, <:Tuple}() where {K, V} = new{K, V, Tuple{}, Tuple{}}((), ())
4646
LittleDict{K, V, KS, VS}() where {K, V, KS, VS} = LittleDict{K, V, KS, VS}(KS(), VS())
4747
end
48+
LittleDict{K, V, KS, VS}(d::AbstractDict) where {K, V, KS<:StoreType{K}, VS<:StoreType{V}} = LittleDict{K, V, KS, VS}(collect(keys(d)), collect(values(d)))
4849

4950
function LittleDict{K,V}(ks::KS, vs::VS) where {K,V, KS<:StoreType,VS<:StoreType}
5051
return LittleDict{K, V, KS, VS}(ks, vs)

test/test_little_dict.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ using OrderedCollections: FrozenLittleDict, UnfrozenLittleDict
119119
@test valtype(dc) == Float64
120120
@test keys(dc) == keys(d)
121121
@test collect(values(dc)) == collect(values(d))
122+
123+
d = Dict(i=>Float32(i) for i = 1:10)
124+
@test convert(LittleDict{Int,Float32}, d) isa LittleDict{Int,Float32}
125+
@test convert(LittleDict{Int,Float32,Vector{Int},Vector{Float32}}, d) isa LittleDict{Int,Float32,Vector{Int},Vector{Float32}}
122126
end
123127

124128
@testset "Issue #60" begin

0 commit comments

Comments
 (0)