GithubHelp home page GithubHelp logo

juliacollections / leftchildrightsiblingtrees.jl Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 5.0 33 KB

Memory-efficient representation of a tree with arbitrary number of children/node

License: MIT License

Julia 100.00%

leftchildrightsiblingtrees.jl's People

Contributors

arkoniak avatar dependabot[bot] avatar expandingman avatar juliatagbot avatar oscardssmith avatar oxinabox avatar ranocha avatar timholy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leftchildrightsiblingtrees.jl's Issues

Cannot `convert` an object of type Node{T} to an object of type T

I am having trouble figuring out what the convert method is supposed to be for a custom struct.

using Parameters
using LeftChildRightSiblingTrees

@with_kw struct DigitalContour
    id::Int = 0
    is_outer::Bool = false
    pixels::Vector{CartesianIndex{2}} = Vector{CartesianIndex{2}}(undef, 0)
end

root = Node(DigitalContour(is_outer = false))
addchild(root, Node(DigitalContour(id = 1)))

ERROR: MethodError: Cannot convert an object of type Node{DigitalContour} to an object of type DigitalContour
Closest candidates are:
convert(::Type{T}, ::T) where T at essentials.jl:168
DigitalContour(::Any, ::Any, ::Any) at /home/zygmunt/.julia/packages/Parameters/l76EM/src/Parameters.jl:478
Stacktrace:
[1] Node{DigitalContour}(::Node{DigitalContour}, ::Node{DigitalContour}) at /home/zygmunt/.julia/packages/LeftChildRightSiblingTrees/7aS8D/src/LeftChildRightSiblingTrees.jl:45
[2] Node(::Node{DigitalContour}, ::Node{DigitalContour}) at /home/zygmunt/.julia/packages/LeftChildRightSiblingTrees/7aS8D/src/LeftChildRightSiblingTrees.jl:52
[3] addchild(::Node{DigitalContour}, ::Node{DigitalContour}) at /home/zygmunt/.julia/packages/LeftChildRightSiblingTrees/7aS8D/src/LeftChildRightSiblingTrees.jl:90
[4] top-level scope at none:0

Part of my problem is that I don't really understand how the call to convert is being called. Thanks for any advice you might have.

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

OK to register?

Do the other JuliaCollections folks think this is ready to register as a package?

Unintuitive AbstractTrees.children implementation

The current implementation simply returns the current Node, which of course works fine because it is iterable.
It is also kind of confusing because children(node) === node looks strange. I briefly thought

children(n::Node) = (c for c in n)

would be nicer, but it turns out that doesn't work with AbstractTrees:

julia> AbstractTrees.print_tree(flamegraph())
FlameGraphs.NodeData(ip:0x0, 0x01, 1:299)
ERROR: MethodError: no method matching keys(::Base.Generator{Node{FlameGraphs.NodeData},var"#9#10"})
Closest candidates are:
  keys(::Core.SimpleVector) at essentials.jl:602
  keys(::Cmd) at process.jl:639
  keys(::Tuple) at tuple.jl:46
  ...
Stacktrace:
 [1] pairs(::Base.Generator{Node{FlameGraphs.NodeData},var"#9#10"}) at ./abstractdict.jl:132

An array comprehension is fine, of course, but also allocates an array.

So yeah, all in all I'm how actionable that complaint is, but the current behaviour was confusing for me at least.

NodeType not defined

Precompilation failure seems to happen with [email protected] but not @0.1.5. Root cause seems to be in LeftChildRightSiblingTrees.

Thanks!

[ Info: Precompiling TerminalLoggers [5d786b92-1e48-4d6f-9151-6b4477ca9bed]
ERROR: LoadError: UndefVarError: NodeType not defined
Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base ./Base.jl:31
 [2] top-level scope
   @ ~/.julia/packages/LeftChildRightSiblingTrees/ItTnK/src/abstracttrees.jl:3
 [3] include(mod::Module, _path::String)
   @ Base ./Base.jl:419
 [4] include(x::String)
   @ LeftChildRightSiblingTrees ~/.julia/packages/LeftChildRightSiblingTrees/ItTnK/src/LeftChildRightSiblingTrees.jl:1
 [5] top-level scope
   @ ~/.julia/packages/LeftChildRightSiblingTrees/ItTnK/src/LeftChildRightSiblingTrees.jl:250
 [6] include
   @ ./Base.jl:419 [inlined]
 [7] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::String)
   @ Base ./loading.jl:1554
 [8] top-level scope
   @ stdin:1

Insert Nodes as Children/Siblings

Right now, addchild and addsibling require you to pass the data directly. Is it reasonable to add methods which allow you to specify child::Node{T}s rather than data::T?

I'm working with a problem where the end product is conveniently represented as a LCRS tree, but it's most sensible to build it from the bottom up, rather than the top down. This means I want to pass a subtree as a child rather than just the data, because that node has a collection of children/siblings already. Presumably we could do this with making Node{T}s which duplicate data and then graftchildren! to this duplicate node, but it seems like we could this more directly

E- This runs into the issue where you could add a Node from a tree to the tree again somewhere else, so it's not necessarily safe. That might be enough to disqualify this

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.