Skip to content

Commit

Permalink
Don't do breaking changes to CleverDicts
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Feb 23, 2021
1 parent fd36aab commit e69921f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/Utilities/CleverDicts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mutable struct CleverDict{K,V,F<:Function,I<:Function} <: AbstractDict{K,V}
end
end
function CleverDict{K,V}(n::Integer = 0) where {K,V}
return CleverDict{K,V}(key_to_index, index_to_key, n)
return CleverDict{K,V}(key_to_index, Base.Fix1(index_to_key, K), n)
end

"""
Expand Down Expand Up @@ -116,7 +116,7 @@ function add_item(c::CleverDict{K,V}, val::V)::K where {K,V}
error("Keys were added out of order. `add_item` requires that keys are always added in order.")
end
# adding a key in order
key = c.inverse_hash(K, Int64(c.last_index + 1))::K
key = c.inverse_hash(Int64(c.last_index + 1))::K
c[key] = val
return key
end
Expand Down Expand Up @@ -144,7 +144,7 @@ end

function Base.keys(c::CleverDict{K}) where {K}
return if _is_dense(c)
[c.inverse_hash(K, index) for index in c.set]
[c.inverse_hash(Int64(index))::K for index in c.set]
else
collect(keys(c.dict))
end
Expand Down Expand Up @@ -284,7 +284,7 @@ function Base.iterate(
return nothing
else
el, i = itr
new_el = c.inverse_hash(K, Int64(el))::K => c.vector[el]::V
new_el = c.inverse_hash(Int64(el))::K => c.vector[el]::V
@static if VERSION >= v"1.4.0"
return new_el, State(i[2], i[1])
else
Expand Down Expand Up @@ -318,7 +318,7 @@ function Base.iterate(
return nothing
else
el, i = itr
new_el = c.inverse_hash(K, Int64(el))::K => c.vector[el]::V
new_el = c.inverse_hash(Int64(el))::K => c.vector[el]::V
@static if VERSION >= v"1.4.0"
return new_el, State(i[2], i[1])
else
Expand Down
28 changes: 14 additions & 14 deletions src/Utilities/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -530,34 +530,34 @@ function MOI.modify(
end

function MOI.set(
model::AbstractModel,
::AbstractModel,
::MOI.ConstraintFunction,
ci::CI{MOI.SingleVariable},
change::MOI.AbstractFunction,
::CI{MOI.SingleVariable},
::MOI.SingleVariable,
)
return throw(MOI.SettingSingleVariableFunctionNotAllowed())
end
function MOI.set(
model::AbstractModel,
attr::MOI.ConstraintFunction,
ci::MOI.ConstraintIndex{F},
func::F,
) where {F,S}
return MOI.set(constraints(model, ci), attr, ci, func)
attr::Union{MOI.ConstraintFunction, MOI.ConstraintSet},
ci::MOI.ConstraintIndex,
func_or_set,
)
return MOI.set(constraints(model, ci), attr, ci, func_or_set)
end
function MOI.set(
model::AbstractModel,
model::AbstractModel{T},
::MOI.ConstraintSet,
ci::CI{MOI.SingleVariable},
change::MOI.AbstractSet,
)
set::SUPPORTED_VARIABLE_SCALAR_SETS{T},
) where {T}
MOI.throw_if_not_valid(model, ci)
flag = single_variable_flag(typeof(change))
flag = single_variable_flag(typeof(set))
if !iszero(flag & LOWER_BOUND_MASK)
model.lower_bound[ci.value] = extract_lower_bound(change)
model.lower_bound[ci.value] = extract_lower_bound(set)
end
if !iszero(flag & UPPER_BOUND_MASK)
model.upper_bound[ci.value] = extract_upper_bound(change)
model.upper_bound[ci.value] = extract_upper_bound(set)
end
end
function MOI.set(
Expand Down
4 changes: 3 additions & 1 deletion src/Utilities/vector_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
# updated.

struct VectorOfConstraints{F<:MOI.AbstractFunction,S<:MOI.AbstractSet} <: MOI.ModelLike
constraints::CleverDicts.CleverDict{MOI.ConstraintIndex{F,S},Tuple{F,S},typeof(CleverDicts.key_to_index),typeof(CleverDicts.index_to_key)}
# FIXME It is not ideal that we have `DataType` here, it might induce type instabilities.
# We should change `CleverDicts` so that we can just use `typeof(CleverDicts.index_to_key)` here.
constraints::CleverDicts.CleverDict{MOI.ConstraintIndex{F,S},Tuple{F,S},typeof(CleverDicts.key_to_index),Base.Fix1{typeof(CleverDicts.index_to_key),DataType}}
function VectorOfConstraints{F,S}() where {F,S}
return new{F,S}(CleverDicts.CleverDict{MOI.ConstraintIndex{F,S},Tuple{F,S}}())
end
Expand Down

0 comments on commit e69921f

Please sign in to comment.