JuliaCollections / JuliaCollections/DataStructures.jl

Pushing subtypes to heaps doesn't work

Open
#648 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Julia
Stars
745
Forks
261
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the provided Julia example with MutableBinaryMinHeap and inspect MutableBinaryHeapNode handling during push!. Determine why a node parameterized by SEvent cannot be converted to the heap's Any node type. Done means parametrized SEvent values can be pushed successfully and retain the expected heap ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.