/** * Branch length utility method. * */ protected function _min_max_branches(EE_TreeNode $tree) { $it = new RecursiveIteratorIterator(new ParseNodeIterator(array($tree)), RecursiveIteratorIterator::LEAVES_ONLY); $shortest = INF; $longest = 0; foreach ($it as $leaf) { $depth = $it->getDepth(); if ($tree->is_root()) { $depth -= 1; } if ($depth < $shortest) { $shortest = $depth; } if ($depth > $longest) { $longest = $depth; } } if (is_infinite($shortest)) { $shortest = 0; } return compact('shortest', 'longest'); }
/** * Branch length utility method. * */ protected function _find_longest_branch(EE_TreeNode $tree) { $it = new RecursiveIteratorIterator(new ParseNodeIterator(array($tree)), RecursiveIteratorIterator::LEAVES_ONLY); $longest = 0; foreach ($it as $leaf) { $depth = $it->getDepth(); if ($tree->is_root()) { $depth -= 1; } if ($depth > $longest) { $longest = $depth; } } return $longest; }