JuliaCollections / JuliaCollections/AbstractTrees.jl
`treemap` is broken?
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 243
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
It looks like treemap is broken or at least maybe documentation example is needed?
using AbstractTrees
import AbstractTrees: children
struct Node
v::Int
c::Vector{Node}
end
children(n::Node) = n.c
tree = Node(1,
[Node(2,
[Node(3, []),
Node(4, [])]),
Node(5, [])])
With this setup, I wasn't able to run treemap in any configuration. FIrst of all, it accepts only PostOrderDFS types. Why can't I just pass tree and it internally call PostOrderDFS on it?
Secondly, call like this
treemap(x -> x.v, PostOrderDFS(tree))
return error
ERROR: MethodError: no method matching keys(::PostOrderDFS{Node})
Closest candidates are:
keys(::Core.SimpleVector) at essentials.jl:605
keys(::Cmd) at process.jl:639
keys(::LibGit2.GitTree) at /home/skoffer/.julia/packages/Revise/XFtoQ/src/git.jl:52
...
Stacktrace:
[1] pairs(::PostOrderDFS{Node}) at ./abstractdict.jl:134
[2] treemap(::var"#19#20", ::PostOrderDFS{Node}) at /home/skoffer/.julia/packages/AbstractTrees/VQ0nX/src/iteration.jl:349
I can pirate it to ( I am completely at loss, what I am doing at this moment, actually)
Base.:pairs(x::PostOrderDFS) = enumerate(x)
This helps to go through this error, but it looks like function require more than one argument, so I change call to
treemap((i, x, c) -> x.v, PostOrderDFS(tree))
And then I get into error
ERROR: MethodError: no method matching copy!(::Array{Int64,1}, ::Int64, ::Array{Union{},1}, ::Int64, ::Int64)
Closest candidates are:
copy!(::AbstractArray{T,1} where T, ::AbstractArray{T,1} where T) at abstractarray.jl:708
copy!(::AbstractArray, ::AbstractArray) at abstractarray.jl:711
Stacktrace:
[1] treemap(::var"#23#24", ::PostOrderDFS{Node}) at /home/skoffer/.julia/packages/AbstractTrees/VQ0nX/src/iteration.jl:369
Help shows that it is true, there is no copy! with 5 arguments in Base.
So, how this function is supposed to be used? Is it working at all?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the Julia example and inspect treemap in iteration.jl, especially the code at the reported lines 349 and 369. Check how its traversal and callback arguments interact with PostOrderDFS and Base.copy!, then establish a supported call or document the required usage; done means the example runs without piracy or method errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100