Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Utilities/CleverDicts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ Base.haskey(::CleverDict, key) = false
# Here, we implement the iterate functions for our `CleverDict`. For either
# backend (`OrderedDict` or `Vector`+`BitSet`) we return the same State type
# so that `iterate` returns the same
# type regardless of the backing datastructure. To help inference, we annotate
# the return type.
# type regardless of the backing datastructure. To help inference, we convert
# the return type. Don't use a type-assertion because this doesn't support `V`
# being an abstract type.

struct State
int::Int64
Expand Down Expand Up @@ -288,7 +289,7 @@ function Base.iterate(
return nothing
else
el, i = itr
return el::Pair{K, V}, State(i)
return convert(Pair{K, V}, el), State(i)
end
end
end
Expand Down Expand Up @@ -318,7 +319,7 @@ function Base.iterate(
return nothing
else
el, i = itr
return el::Pair{K, V}, State(i)
return convert(Pair{K, V}, el), State(i)
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions test/Utilities/CleverDicts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ CleverDicts.index_to_key(::Type{MyKey}, index::Int) = MyKey{index}()
@test d[MyKey{1}()] == "first"
end

@testset "Abstract Value" begin
d = CleverDicts.CleverDict{MathOptInterface.VariableIndex, Any}()
key = CleverDicts.add_item(d, :a)
@test key == MathOptInterface.VariableIndex(1)
@test d[MathOptInterface.VariableIndex(1)] == :a
key = CleverDicts.add_item(d, "b")
@test key == MathOptInterface.VariableIndex(2)
@test d[MathOptInterface.VariableIndex(2)] == "b"
for (k, v) in d
if k.value == 1
@test v == :a
else
@test k.value == 2
@test v == "b"
end
end
end

@testset "get/set" begin
d = CleverDicts.CleverDict{MathOptInterface.VariableIndex, String}()
key = CleverDicts.add_item(d, "first")
Expand Down