@@ -87,9 +87,30 @@ NodeTypeUnknown
8787HasNodeType
8888```
8989
90- This can be used e.g. to guarantee the ` eltype ` of ` TreeIterator ` s. It should be defined especially
91- for trees in which all nodes have the same type, which are the only cases in which iteration over a
92- tree can be type stable.
90+ Providing the ` HasNodeType ` trait will guarantee that all nodes connected to the node must be of the
91+ type returned by [ ` nodetype ` ] ( @ref ) .
92+
93+ An important use case of this trait is to guarantee the return types of a ` TreeIterator ` . Tree
94+ nodes with ` NodeTypeUnknown ` cannot have type-stable iteration over the entire tree.
95+
96+ For example
97+ ``` julia
98+ struct ExampleNode
99+ x:: Int
100+ children:: Vector{ExampleNode}
101+ end
102+
103+ AbstractTrees. nodevalue (x:: ExampleNode ) = x. x
104+ AbstractTrees. children (x:: ExampleNode ) = x. children
105+
106+ AbstractTrees. NodeType (:: Type{<:ExampleNode} ) = HasNodeType ()
107+ AbstractTrees. nodetype (:: Type{<:ExampleNode} ) = ExampleNode
108+ ```
109+ In this example, iteration over a tree of ` ExampleNode ` s is type-stable with ` eltype `
110+ ` ExampleNode ` .
111+
112+ Providing the ` nodetype(::Type) ` method is preferable to defining ` nodetype(::ExampleNode) ` because
113+ it ensures that ` nodetype ` can be involved at compile time even if values are not known.
93114
94115
95116## The Indexed Tree Interface
@@ -124,9 +145,25 @@ prevsiblingindex
124145rootindex
125146```
126147
148+ ## Additional Functions
149+ ``` @docs
150+ getdescendant
151+ nodevalues
152+ ischild
153+ isroot
154+ intree
155+ isdescendant
156+ treebreadth
157+ treeheight
158+ descendleft
159+ getroot
160+ ```
161+
127162## Example Implementations
128163- All objects in base which define the abstract trees interface are defined in
129164 [ ` builtins.jl ` ] ( https://github.com/JuliaCollections/AbstractTrees.jl/blob/master/src/builtins.jl ) .
130- - [ ` IDTree ` ] ( https://github.com/JuliaCollections/AbstractTrees.jl/blob/master/test/idtree.jl )
131- - [ ` OneNode ` ] ( https://github.com/JuliaCollections/AbstractTrees.jl/blob/master/test/onenode.jl )
132- - [ ` OneTree ` ] ( https://github.com/JuliaCollections/AbstractTrees.jl/blob/master/test/onetree.jl )
165+ - [ ` IDTree ` ] ( https://github.com/JuliaCollections/AbstractTrees.jl/blob/master/test/examples/idtree.jl )
166+ - [ ` OneNode ` ] ( https://github.com/JuliaCollections/AbstractTrees.jl/blob/master/test/examples/onenode.jl )
167+ - [ ` OneTree ` ] ( https://github.com/JuliaCollections/AbstractTrees.jl/blob/master/test/examples/onetree.jl )
168+ - [ ` FSNode ` ] ( https://github.com/JuliaCollections/AbstractTrees.jl/blob/master/test/examples/fstree.jl )
169+ - [ ` BinaryNode ` ] ( https://github.com/JuliaCollections/AbstractTrees.jl/blob/master/test/examples/binarytree.jl )
0 commit comments