I’m not sure, but if you actually wanted sorted containers, they are here (none that I know of are in the standard library Base, meaning in Julia; that package can however be seen as the standard):
https://juliacollections.github.io/DataStructures.jl/v0.9/sorted_containers.html
Arrays (and lists, neither in Julia Base; available in the package above) are naturally ordered. Dicts (and sets), are often unordered, there’s are many different kinds, some unordered, some ordered, some sorted, while only unordered Dict
and Set
are in the standard library, meaning Julia Base.
For ordered dict, the most used is OrderedDict (while it’s not the fastest option).
E.g. unlike:
julia> d = Dict("A" => 1, "B" => 2)
Dict{String,Int64} with 2 entries:
"B" => 2
"A" => 1
You see it right away, this time, I guess you have a 50% change, for two values (it seems lower, just beware) of actually unordered, at least not for:
d = Dict("B" =>2, "C" => 3)
Dict{String,Int64} with 2 entries:
"B" => 2
"C" => 3
And deceptively push!
seems to add to the end:
julia> push!(d, "C" => 3)
Dict{String,Int64} with 3 entries:
"B" => 2
"C" => 3
The pattern seems to hold adding for the next 3 push!, until:
julia> push!(d, "G" => 7)
Dict{String,Int64} with 7 entries:
"B" => 2
"C" => 3
"D" => 4
"G" => 7
"E" => 5
"F" => 6