/* ---------------------------------------------------------------------------- Recursive routines for the TreeBASE objects ---------------------------------------------------------------------------- */ static int _GATreeSize(GANodeBASE * node) { if(!node) return 0; int count = 1 + _GATreeSize(node->child); for(GANodeBASE * tmp=node->next; tmp && tmp != node; tmp=tmp->next){ count++; count += _GATreeSize(tmp->child); } return count; }
// Return the number of nodes in the tree. We do a complete traversal of the // tree and count the number of nodes that we encounter. Could do this breadth // first or depth first - doesn't really matter. We have to traverse the // entire tree to do the count. // We have to do a little work-around here to get through the const-ness of // the size method. Its ok to call size on a const object because it does not // modify the logical state of the object. It does, however, modify the // physical state of the object. So to work around the strictness of the // const specifier, we do a little pointer magic and cast this to be non-const. int GATreeBASE::size() const { if(!csz) return sz; GATreeBASE * This = (GATreeBASE *)this; This->csz = 0; return(This->sz = _GATreeSize(rt)); }
// Return the number of nodes in the tree. We do a complete traversal of the // tree and count the number of nodes that we encounter. Could do this breadth // first or depth first - doesn't really matter. We have to traverse the // entire tree to do the count. // We have to do a little work-around here to get through the const-ness of // the size method. Its ok to call size on a const object because it does not // modify the logical state of the object. It does, however, modify the // physical state of the object. So to work around the strictness of the // const specifier, we do a little pointer magic and cast this to be non-const. int GATreeBASE::size() const { if(!csz) return sz; GATreeBASE * This = CON_CAST(GATreeBASE *, this); This->csz = 0; return(This->sz = _GATreeSize(rt)); }
/// Return the number of nodes in the tree from the specified node on down. /// Similar to the TreeBASE size method, but we don't set the sz member and /// we can't cache the size since this could be called on any node. int GATreeIterBASE::size(GANodeBASE * n) { return(_GATreeSize(n)); }