Skip to content

Commit

Permalink
Use Dict constructor in new_ordered_dict
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Nov 20, 2018
1 parent 616ad67 commit 7c491c6
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 7c491c6

Please sign in to comment.