function tripal_phylogeny_assign_tree_indices

2.x tripal_phylogeny.import_tree.inc tripal_phylogeny_assign_tree_indices(&$tree, &$index = 1)

Iterates through the tree and sets the left and right indicies .

Parameters

$tree: The tree array.

$index: This parameters is not used when the function is first called. It is used for recursive calls.

2 calls to tripal_phylogeny_assign_tree_indices()

File

tripal_phylogeny/includes/tripal_phylogeny.import_tree.inc, line 145

Code

function tripal_phylogeny_assign_tree_indices(&$tree, &$index = 1) {
  // Assign a left and right index to each node.  The child node must
  // have a right and left index less than that of it's parents.  We
  // increment the index by 100 to give space for new nodes that might
  // be added later.
  if (array_key_exists('name', $tree)) {
    $tree['left_index'] = $index += 100;
    if (array_key_exists('is_leaf', $tree)) {
      $tree['right_index'] = $index += 100;
    }
  }
  if (array_key_exists('branch_set', $tree)) {
    foreach ($tree['branch_set'] as $key => $node) {
      tripal_phylogeny_assign_tree_indices($tree['branch_set'][$key], $index);
      $tree['right_index'] = $index += 100;
    }
  }
}