• Stars
    star
    198
  • Rank 195,334 (Top 4 %)
  • Language
    Julia
  • License
    Other
  • Created about 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Abstract julia interfaces for working with trees

AbstractTrees

Build Status codecov

A package for dealing with generalized tree-like data structures.

Examples

julia> t = [[1,2], [3,4]];  # AbstractArray and AbstractDict are trees

julia> children(t)
2-element Vector{Vector{Int64}}:
 [1, 2]
 [3, 4]

julia> getdescendant(t, (2,1))
3

julia> collect(PreOrderDFS(t))  # iterate from root to leaves
7-element Vector{Any}:
  [[1, 2], [3, 4]]
  [1, 2]
 1
 2
  [3, 4]
 3
 4

julia> collect(PostOrderDFS(t))  # iterate from leaves to root
7-element Vector{Any}:
 1
 2
  [1, 2]
 3
 4
  [3, 4]
  [[1, 2], [3, 4]]

julia> collect(Leaves(t))  # iterate over leaves
4-element Vector{Int64}:
 1
 2
 3
 4

julia> struct FloatTree  # make your own trees
        x::Float64
        children::Vector{FloatTree}
    end;

julia> AbstractTrees.children(t::FloatTree) = t.children;

julia> AbstractTrees.nodevalue(t::FloatTree) = t.x;

julia> print_tree(FloatTree(NaN, [FloatTree(Inf, []), FloatTree(-Inf, [])]))
NaN
β”œβ”€ Inf
└─ -Inf

Related Packages

  • D3Trees.jl provides interactive rendering of large trees using the D3.js javascript package.