comparison src/StaticDicts/StaticDicts.jl @ 726:103f61d09a8b feature/static_dict

More documentation
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 17 Mar 2021 20:21:36 +0100
parents e5b51c82f83b
children 3e0b0b44868e
comparison
equal deleted inserted replaced
725:e5b51c82f83b 726:103f61d09a8b
11 The immutable nature means that `StaticDict`s can be compared with `==`, in 11 The immutable nature means that `StaticDict`s can be compared with `==`, in
12 constrast to regular `Dict`s or `ImmutableDict`s which can not. (See 12 constrast to regular `Dict`s or `ImmutableDict`s which can not. (See
13 https://github.com/JuliaLang/julia/issues/4648 for details) 13 https://github.com/JuliaLang/julia/issues/4648 for details)
14 14
15 Lookups are done by linear search. 15 Lookups are done by linear search.
16
17 Duplicate keys are not allowed and an error will be thrown if they are passed
18 to the constructor.
16 """ 19 """
17 struct StaticDict{K,V,N} <: AbstractDict{K,V} 20 struct StaticDict{K,V,N} <: AbstractDict{K,V}
18 pairs::NTuple{N,Pair{K,V}} 21 pairs::NTuple{N,Pair{K,V}}
19 22
20 # TBD: Why doesn't `pairs::NTuple{N,Pair{K,V}}` work? 23 # TBD: Why doesn't `pairs::NTuple{N,Pair{K,V}}` work?
48 Base.iterate(d::StaticDict, state) = iterate(d.pairs,state) 51 Base.iterate(d::StaticDict, state) = iterate(d.pairs,state)
49 52
50 Base.length(d::StaticDict) = length(d.pairs) 53 Base.length(d::StaticDict) = length(d.pairs)
51 54
52 55
53 # TODO documentation: duplicate keys not allowed atm. will error 56 """
57 merge(d1::StaticDict, d2::StaticDict)
58
59 Merge two `StaticDict`. Repeating keys is considered and error. This may
60 change in a future version.
61 """
54 function Base.merge(d1::StaticDict, d2::StaticDict) 62 function Base.merge(d1::StaticDict, d2::StaticDict)
55 return StaticDict(d1.pairs..., d2.pairs...) 63 return StaticDict(d1.pairs..., d2.pairs...)
56 end 64 end
57 65
58 66