@@ -776,20 +776,60 @@ struct ImmutableDict{K,V} <: AbstractDict{K,V}
776
776
end
777
777
778
778
"""
779
- ImmutableDict
779
+ ImmutableDict(key=>value, key=>value, ...)
780
780
781
- `ImmutableDict` is a dictionary implemented as an immutable linked list,
782
- which is optimal for small dictionaries that are constructed over many individual insertions.
783
- Note that it is not possible to remove a value, although it can be partially overridden and hidden
784
- by inserting a new value with the same key.
781
+ `ImmutableDict{K,V}()`
785
782
786
- ImmutableDict(KV::Pair)
783
+ `ImmutableDict` is a dictionary implemented as an immutable linked
784
+ list, used for small mappings with a few entries where the overhead
785
+ of accessing a hash table is higher than that of a linear search of a
786
+ linked list.
787
787
788
- Create a new entry in the `ImmutableDict` for a `key => value` pair
788
+ Base.ImmutableDict(key=>value, key=>value, ...)
789
+
790
+ `Base.ImmutableDict(key=>value, key=>value, ...)` constructs a linked
791
+ list; the first argument sets the type of the keys and values. Keys
792
+ are compared with `isequal`.
793
+
794
+ `Base.ImmutableDict{K,V}()` constructs an empty list with keys of type
795
+ K and values of type V.
796
+
797
+ Base.ImmutableDict(imdict, key=>value, key=>value, ...)
798
+
799
+ `Base.ImmutableDict(imdict, key=>value, key=>value, ...)` constructs a
800
+ new `ImmutableDict` from an existing `ImmutableDict` and additional KV
801
+ pairs, returning a new list. The original `ImmutableDict` becomes the
802
+ tail of the new list.
803
+
804
+ Pairs cannot be removed from an immutable dictionary, but they can be
805
+ shadowed by adding an additional pair with a duplicate key; indexing
806
+ operations will find the the last key added.
789
807
790
808
- use `(key => value) in dict` to see if this particular combination is in the properties set
791
809
- use `get(dict, key, default)` to retrieve the most recent value for a particular key
792
810
811
+ # Examples
812
+
813
+ julia> ctypes = Base.ImmutableDict("char"=>:char, "int"=>:int)
814
+ Base.ImmutableDict{String, Symbol} with 2 entries:
815
+ "int" => :int
816
+ "char" => :char
817
+
818
+ julia> ctypes = Base.ImmutableDict(ctypes, "float"=>:float, "double"=>:double)
819
+ Base.ImmutableDict{String, Symbol} with 4 entries:
820
+ "double" => :double
821
+ "float" => :float
822
+ "int" => :int
823
+ "char" => :char
824
+
825
+ julia> viewparameters = Base.ImmutableDict{String,Any}()
826
+ Base.ImmutableDict{String, Any}()
827
+
828
+ julia> viewparameters = Base.ImmutableDict(
829
+ viewparameters, "type"=>"perspective", "direction"=>(0, 0, 1))
830
+ Base.ImmutableDict{String, Any} with 2 entries:
831
+ "direction" => (0, 0, 1)
832
+ "type" => "perspective"
793
833
"""
794
834
ImmutableDict
795
835
ImmutableDict (KV:: Pair{K,V} ) where {K,V} = ImmutableDict {K,V} (KV[1 ], KV[2 ])
0 commit comments