OrderedDict
/ DefaultOrderedDict
are not correct since they refer to insertion order. What you want is SortedDict
:
julia> d = SortedDict{Int64,Float64}();
julia> d[8] = 34;
julia> d[-3] = 12;
julia> d
SortedDict{Int64,Float64,Base.Order.ForwardOrdering} with 2 entries:
-3 => 12.0
8 => 34.0
As for “if the program attempts to set bucket[-3] to something, it will be inserted”, this is done by simply setting d[-3] = something
(as in the example above).
Be aware that I’ve had mixed experience with DataStructures.jl
when it comes to performance. In particular, for SortedDict
you might be better off using a regular Dict
(or Vector
of tuples if you don’t need the dictionary properties) and sort the objects when you need them in order.