@@ -9,7 +9,16 @@ abstract type AbstractDoubleDict{V} <: AbstractDict{MOI.ConstraintIndex,V} end
99abstract type AbstractDoubleDictInner{F,S,V} < :
1010 AbstractDict{MOI. ConstraintIndex{F,S},V} end
1111
12- _inner (d:: AbstractDoubleDictInner ) = d. inner
12+ """
13+ typed_value(dict::AbstractDoubleDictInner{F,S,V}, value) where {F,S,V}
14+
15+ Convert the `value` stored inside `dict` to the equivalent on the outer
16+ `DoubleDict`. This is useful when the value type `V` of the inner dict is
17+ different to the outer dict. (See, e.g., [`IndexDoubleDict`](@ref).)
18+ """
19+ function typed_value (:: AbstractDoubleDictInner{F,S,V} , value:: V ) where {F,S,V}
20+ return value
21+ end
1322
1423"""
1524 DoubleDict{V}
@@ -83,32 +92,10 @@ mutable struct IndexDoubleDictInner{F,S} <:
8392 end
8493end
8594
86- # _typed_value
87-
88- @inline function _typed_value (:: DoubleDictInner{F,S,V} , v:: V ) where {F,S,V}
89- return v
90- end
91-
92- @inline function _typed_value (:: IndexDoubleDictInner{F,S} , v:: Int64 ) where {F,S}
95+ function typed_value (:: IndexDoubleDictInner{F,S} , v:: Int64 ) where {F,S}
9396 return MOI. ConstraintIndex {F,S} (v)
9497end
9598
96- # _reverse_dict
97-
98- # reversing IndexDoubleDict is ok because they map CI to CI
99- function MOI. Utilities. _reverse_dict (
100- dest:: IndexDoubleDict ,
101- src:: IndexDoubleDict ,
102- )
103- for (key, value) in src. dict
104- dest. dict[key] = MOI. Utilities. _reverse_dict (value)
105- end
106- return
107- end
108- # reversing other double dict types is not ok because the map CI fo K
109- # so it wont be a double dict anymore, double dict keys are always CIs.
110- # We keep the default fallback
111-
11299# Base.sizehint!
113100
114101function Base. sizehint! (:: AbstractDoubleDict , :: Integer )
@@ -122,7 +109,7 @@ function Base.sizehint!(::AbstractDoubleDict, ::Integer)
122109end
123110
124111function Base. sizehint! (d:: AbstractDoubleDictInner , n:: Integer )
125- return sizehint! (_inner (d) , n)
112+ return sizehint! (d . inner , n)
126113end
127114
128115# Base.length
@@ -135,7 +122,7 @@ function Base.length(d::AbstractDoubleDict)
135122 return len
136123end
137124
138- Base. length (d:: AbstractDoubleDictInner ) = length (_inner (d) )
125+ Base. length (d:: AbstractDoubleDictInner ) = length (d . inner )
139126
140127# Base.haskey
141128
@@ -150,7 +137,7 @@ function Base.haskey(
150137 d:: AbstractDoubleDictInner{F,S} ,
151138 key:: MOI.ConstraintIndex{F,S} ,
152139) where {F,S}
153- return haskey (_inner (d) , key. value)
140+ return haskey (d . inner , key. value)
154141end
155142
156143# Base.get
@@ -185,11 +172,10 @@ function Base.getindex(
185172 d:: AbstractDoubleDictInner{F,S} ,
186173 key:: MOI.ConstraintIndex{F,S} ,
187174) where {F,S}
188- inner = _inner (d)
189- if ! haskey (inner, key. value)
175+ if ! haskey (d. inner, key. value)
190176 throw (KeyError (key))
191177 end
192- return _typed_value (d, inner[key. value])
178+ return typed_value (d, d . inner[key. value])
193179end
194180
195181function Base. getindex (d:: IndexDoubleDict , :: Type{F} , :: Type{S} ) where {F,S}
@@ -213,7 +199,7 @@ function Base.setindex!(
213199 value:: V ,
214200 key:: MOI.ConstraintIndex{F,S} ,
215201) where {F,S,V}
216- _inner (d) [key. value] = value
202+ d . inner [key. value] = value
217203 return value
218204end
219205
@@ -232,7 +218,7 @@ function Base.setindex!(
232218 value:: MOI.ConstraintIndex{F,S} ,
233219 key:: MOI.ConstraintIndex{F,S} ,
234220) where {F,S}
235- _inner (d) [key. value] = value. value
221+ d . inner [key. value] = value. value
236222 return value
237223end
238224
@@ -244,7 +230,7 @@ function Base.empty!(d::AbstractDoubleDict)
244230end
245231
246232function Base. empty! (d:: AbstractDoubleDictInner )
247- empty! (_inner (d) )
233+ empty! (d . inner )
248234 return d
249235end
250236
@@ -262,7 +248,7 @@ function Base.delete!(
262248 d:: AbstractDoubleDictInner{F,S} ,
263249 key:: MOI.ConstraintIndex{F,S} ,
264250) where {F,S}
265- delete! (_inner (d) , key. value)
251+ delete! (d . inner , key. value)
266252 return d
267253end
268254
@@ -272,7 +258,7 @@ function Base.isempty(d::AbstractDoubleDict)
272258 return isempty (d. dict) || all (isempty, values (d. dict))
273259end
274260
275- Base. isempty (d:: AbstractDoubleDictInner ) = isempty (_inner (d) )
261+ Base. isempty (d:: AbstractDoubleDictInner ) = isempty (d . inner )
276262
277263# Base.values
278264
@@ -285,7 +271,7 @@ function Base.values(d::AbstractDoubleDict{V})::Vector{V} where {V}
285271end
286272
287273function Base. values (d:: DoubleDictInner{F,S,V} ):: Vector{V} where {F,S,V}
288- return V[v for v in values (_inner (d) )]
274+ return V[v for v in values (d . inner )]
289275end
290276
291277function Base. values (d:: IndexDoubleDict )
@@ -297,7 +283,7 @@ function Base.values(d::IndexDoubleDict)
297283end
298284
299285function Base. values (d:: IndexDoubleDictInner{F,S} ) where {F,S}
300- return MOI. ConstraintIndex {F,S} .(values (_inner (d) ))
286+ return MOI. ConstraintIndex {F,S} .(values (d . inner ))
301287end
302288
303289# Base.keys
@@ -311,7 +297,7 @@ function Base.keys(d::AbstractDoubleDict)
311297end
312298
313299function Base. keys (d:: AbstractDoubleDictInner{F,S} ) where {F,S}
314- return MOI. ConstraintIndex {F,S} .(keys (_inner (d) ))
300+ return MOI. ConstraintIndex {F,S} .(keys (d . inner ))
315301end
316302
317303# Base.iterate
@@ -336,18 +322,18 @@ function Base.iterate(d::AbstractDoubleDict)
336322 inner_next = iterate (inner)
337323 end
338324 (k, v), inner_state = inner_next
339- result = MOI. ConstraintIndex {F,S} (k) => _typed_value (getindex (d, F, S), v)
325+ result = MOI. ConstraintIndex {F,S} (k) => typed_value (getindex (d, F, S), v)
340326 return result, (inner_state, outer_next)
341327end
342328
343329function Base. iterate (d:: AbstractDoubleDictInner{F,S} ) where {F,S}
344- next = iterate (_inner (d) )
330+ next = iterate (d . inner )
345331 if next === nothing
346332 return
347333 end
348334 (k, v), inner_state = next
349- result = MOI. ConstraintIndex {F,S} (k) => _typed_value (d, v)
350- return result, (_inner (d) , inner_state)
335+ result = MOI. ConstraintIndex {F,S} (k) => typed_value (d, v)
336+ return result, (d . inner , inner_state)
351337end
352338
353339function Base. iterate (d:: AbstractDoubleDict , state)
@@ -366,7 +352,7 @@ function Base.iterate(d::AbstractDoubleDict, state)
366352 inner_next = iterate (inner)
367353 end
368354 (k, v), inner_state = inner_next
369- result = MOI. ConstraintIndex {F,S} (k) => _typed_value (getindex (d, F, S), v)
355+ result = MOI. ConstraintIndex {F,S} (k) => typed_value (getindex (d, F, S), v)
370356 return result, (inner_state, outer_next)
371357end
372358
@@ -377,7 +363,7 @@ function Base.iterate(d::AbstractDoubleDictInner{F,S}, state) where {F,S}
377363 return
378364 end
379365 ((k, v), next_inner_state) = next
380- result = MOI. ConstraintIndex {F,S} (k) => _typed_value (d, v)
366+ result = MOI. ConstraintIndex {F,S} (k) => typed_value (d, v)
381367 return result, (inner, next_inner_state)
382368end
383369
0 commit comments