@@ -55,7 +55,7 @@ mutable struct Node{N<:AbstractNodeMTG,A}
5555 " Node attributes. Can be anything really"
5656 attributes:: A
5757 " Cache for mtg nodes traversal"
58- traversal_cache:: Dict{String,Vector{Node{N,A}}}
58+ traversal_cache:: Union {Nothing, Dict{String,Vector{Node{N,A} }}}
5959end
6060
6161# All deprecated methods (the ones with a node name) :
6868
6969function Node (id:: Int , MTG:: T , attributes:: ColumnarAttrs ) where {T<: AbstractNodeMTG }
7070 node = Node {T,ColumnarAttrs} (
71- id, nothing , Vector {Node{T,ColumnarAttrs}} (), MTG, attributes, Dict {String,Vector{Node{T,ColumnarAttrs}}} ()
71+ id, nothing , Vector {Node{T,ColumnarAttrs}} (), MTG, attributes, nothing
7272 )
7373 init_columnar_root! (attributes, id, getfield (MTG, :symbol ))
7474 return node
101101
102102function Node (id:: Int , parent:: Node{M,ColumnarAttrs} , MTG:: M , attributes:: ColumnarAttrs ) where {M<: AbstractNodeMTG }
103103 node = Node {M,ColumnarAttrs} (
104- id, parent, Vector {Node{M,ColumnarAttrs}} (), MTG, attributes, Dict {String,Vector{Node{M,ColumnarAttrs}}} ()
104+ id, parent, Vector {Node{M,ColumnarAttrs}} (), MTG, attributes, nothing
105105 )
106106 addchild! (parent, node)
107107 bind_columnar_child! (node_attributes (parent), attributes, id, getfield (MTG, :symbol ))
@@ -517,7 +517,16 @@ Base.names(mtg::T) where {T<:MultiScaleTreeGraph.Node} = get_attributes(mtg)
517517
518518Get the traversal cache of the node if any.
519519"""
520- node_traversal_cache (node:: Node ) = getfield (node, :traversal_cache )
520+ @inline _maybe_traversal_cache (node:: Node ) = getfield (node, :traversal_cache )
521+
522+ function node_traversal_cache (node:: Node{T,A} ) where {T,A}
523+ cache = getfield (node, :traversal_cache )
524+ if cache === nothing
525+ cache = Dict {String,Vector{Node{T,A}}} ()
526+ setfield! (node, :traversal_cache , cache)
527+ end
528+ return cache
529+ end
521530
522531Base. getproperty (node:: Node , key:: Symbol ) = unsafe_getindex (node, key)
523532Base. hasproperty (node:: Node , key:: Symbol ) = haskey (node_attributes (node), key)
0 commit comments