comparison src/StaticDicts/StaticDicts.jl @ 724:a789e789e30f feature/static_dict

Docstring for StaticDict
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 17 Mar 2021 20:15:02 +0100
parents 172c55c4cf2e
children e5b51c82f83b
comparison
equal deleted inserted replaced
721:b2af21a4b376 724:a789e789e30f
1 module StaticDicts 1 module StaticDicts
2 2
3 export StaticDict 3 export StaticDict
4 4
5 # Vidar 2021-02-27
6 #NOTE: This type was added since ==-comparison of structs containing
7 # Dict (even Base.ImmutableDict) fails even though the fields satisfy
8 # ==-comparison. This is due to the fact that === is called for Dict-fields.
9 # See https://github.com/JuliaLang/julia/issues/4648. If the PR gets resolved
10 # we should consider removing StaticDict.
11 """ 5 """
12 StaticDict{K,V,N}(NTuple{N,Pair{K,V}}) 6 StaticDict{K,V,N}(NTuple{N,Pair{K,V}}) <: AbstractDict
13 7
14 A simple static dictonary. Performs lookup using linear search with ==-comparison 8 A static dictionary implementing the interface for an `AbstractDict`. A
15 of keys. No hashing is used. 9 `StaticDict` is fully immutable and after creation no changes can be made.
10
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
13 https://github.com/JuliaLang/julia/issues/4648 for details)
14
15 Lookups are done by linear search.
16 """ 16 """
17 struct StaticDict{K,V,N} <: AbstractDict{K,V} 17 struct StaticDict{K,V,N} <: AbstractDict{K,V}
18 pairs::NTuple{N,Pair{K,V}} 18 pairs::NTuple{N,Pair{K,V}}
19 19
20 # TBD: Why doesn't `pairs::NTuple{N,Pair{K,V}}` work? 20 # TBD: Why doesn't `pairs::NTuple{N,Pair{K,V}}` work?