Skip to content

Pushing subtypes to heaps doesn't work #648

Open
@NightMachinery

Description

@NightMachinery

As suggested in this discourse discussion, I am bringing this issue here:

using DataStructures
import Base.isless

struct SEvent{F1}
    callback::F1
    time::Float64
end

function SEvent(callback::F1, time) where F1
    SEvent{F1}(callback, time)
end

function isless(a::SEvent, b::SEvent)
    isless(a.time, b.time)
end

Now I try to put SEvents into a heap:

s1 = SEvent(10) do x
    4
end
s2 = SEvent(3) do x
    5
end
a = MutableBinaryMinHeap{Any}() # Or try {SEvent}, the result will be the same

push!(a,s1)

This will cause an error:

ERROR: LoadError: MethodError: Cannot `convert` an object of type 
  DataStructures.MutableBinaryHeapNode{SEvent{var"#9#10"}} to an object of type 
  DataStructures.MutableBinaryHeapNode{Any}

Is there no way to put a parametrized struct into a parametrized container like a heap?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions