@@ -48,6 +48,7 @@ mutable struct Node{T}
4848 # # Constructors:
4949 # ################
5050 Node (d:: Int , c:: Bool , v:: _T ) where {_T} = new {_T} (d, c, v)
51+ Node (:: Type{_T} , d:: Int , c:: Bool , v:: _T ) where {_T} = new {_T} (d, c, v)
5152 Node (:: Type{_T} , d:: Int , c:: Bool , v:: Nothing , f:: Int ) where {_T} = new {_T} (d, c, v, f)
5253 function Node (d:: Int , c:: Bool , v:: Nothing , f:: Int , o:: Int , l:: Node{_T} ) where {_T}
5354 return new {_T} (d, c, v, f, o, l)
130131function Node (
131132 :: Type{T} ; val:: T1 = nothing , feature:: T2 = nothing
132133):: Node{T} where {T,T1,T2<: Union{Integer,Nothing} }
133- return convert (Node{T}, Node (; val= val, feature= feature))
134+ if T1 <: Nothing && T2 <: Nothing
135+ error (" You must specify either `val` or `feature` when creating a leaf node." )
136+ elseif ! (T1 <: Nothing || T2 <: Nothing )
137+ error (
138+ " You must specify either `val` or `feature` when creating a leaf node, not both." ,
139+ )
140+ elseif T2 <: Nothing
141+ return Node (T, 0 , true , val)
142+ else
143+ return Node (T, 0 , false , nothing , feature)
144+ end
134145end
135146
136147"""
0 commit comments