Skip to content

Commit

Permalink
Merge pull request #1640 from JuliaOpt/bl/new_ordered_dict
Browse files Browse the repository at this point in the history
Use Dict constructor for 1 and 2 arguments new_ordered_dict
  • Loading branch information
blegat committed Nov 20, 2018
2 parents 616ad67 + 7c491c6 commit 2db350a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/aff_expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ function new_ordered_dict(::Type{K}, ::Type{V}, kv::Pair...) where {K,V}
end
return dict
end
# Shortcut for one and two arguments to avoid creating an empty dict and add
# elements one by one with `JuMP.add_or_set!`
function new_ordered_dict(::Type{K}, ::Type{V}, kv::Pair) where {K, V}
return OrderedDict{K, V}(kv)
end
function new_ordered_dict(::Type{K}, ::Type{V}, kv1::Pair, kv2::Pair) where {K, V}
if isequal(kv1.first, kv2.first)
return OrderedDict{K, V}(kv1.first => kv1.second + kv2.second)
else
return OrderedDict{K, V}(kv1, kv2)
end
end



Expand Down

0 comments on commit 2db350a

Please sign in to comment.