Add num_children
to Tree arrays
#2274
Labels
C API
Issue is about the C API
enhancement
New feature or request
Python API
Issue is about the Python API
Milestone
There are lots of times when we want to ask questions about the arity (number of children) of the nodes in a tree. In particular, many of the operations discussed in #2245 required this as input. While it's easy enough to compute in a linear pass through the nodes in the tree, it's also something we can maintain during the tree transition process very cheaply. The basic algorithm just needs to increment/decrement a count for the parent node:
So, the computational cost would essentially be free, and it's just a question about whether we want to add the extra O(num_nodes) space cost to the Tree struct by default or not.
My feeling is that this is quite a basic thing and it'll be annoying to have to specify a Tree option if you want to do things like compute stats based on node arity, so it's probably worth the extra bit of memory.
If we make it a standard part of the tree building process, then we can export it as a numpy array to Python (like the other tree arrays) and then things like computing the arity histogram,
is_binary
etc can be done efficiently in Python.The text was updated successfully, but these errors were encountered: