TreemapNode::getTotalSize PHP Method

getTotalSize() public method

depth first search to get the total number of nodes that are descendants of this node.
public getTotalSize ( )
    public function getTotalSize()
    {
        if (!isset($this->_size)) {
            $size = $this->getSize();
            if (!$this->isLeaf()) {
                foreach ($this->getChildren() as $child) {
                    $size += $child->getTotalSize();
                }
            }
            $this->_size = $size;
        }
        return $this->_size;
    }

Usage Example

 function testGraphDepthSpread()
 {
     $root = new TreemapNode("root", "test");
     $root->putChild(new TreemapNode("child", "test"));
     $childOne = new TreemapNode("child1", "test");
     $childTwo = new TreemapNode("child2", "test");
     $childThree = new TreemapNode("child3", "test");
     $childFour = new TreemapNode("child4", "test");
     $childFive = new TreemapNode("child5", "test");
     $childSix = new TreemapNode("child6", "test");
     $childFour->putChild($childFive);
     $childFour->putChild($childSix);
     $this->assertEqual($childFour->getSize(), 2);
     $this->assertEqual($childFour->getTotalSize(), 2);
     $childThree->putChild($childFour);
     $this->assertEqual($childThree->getSize(), 1);
     $this->assertEqual($childThree->getTotalSize(), 3);
     $childTwo->putChild($childThree);
     $this->assertEqual($childTwo->getSize(), 1);
     $this->assertEqual($childTwo->getTotalSize(), 4);
     $childOne->putChild($childTwo);
     $root->putChild($childOne);
     $this->assertEqual($root->getSize(), 2);
     $this->assertEqual($root->getTotalSize(), 7);
 }
All Usage Examples Of TreemapNode::getTotalSize