Exemplo n.º 1
0
//---------------------------------------------------------
void AsciiTree::compute_rprofile(AsciiNode* ascii_node, int x, int y) 
{
	if(ascii_node==NULL)
		return;

	int notleft;
	notleft=(ascii_node->parent_dir!=-1);
	rprofile[y]=std::max(rprofile[y], x+((ascii_node->lablen-notleft)/2));
	if(ascii_node->right!=NULL) 
		for(int i=1; i<=ascii_node->edge_length && y+i<MAX_HEIGHT; ++i) 
			rprofile[y+i]=std::max(rprofile[y+i], x+i);
	
	compute_rprofile(ascii_node->left, x-ascii_node->edge_length-1, y+ascii_node->edge_length+1);
	compute_rprofile(ascii_node->right, x+ascii_node->edge_length+1, y+ascii_node->edge_length+1);
}
void compute_rprofile(asciinode *node, int x, int y) 
{
  int i, notleft;
  if (node == NULL) return;
  notleft = (node->parent_dir != -1);
  rprofile[y] = MAX(rprofile[y], x+((node->lablen-notleft)/2));
  if (node->right != NULL) 
  {
    for (i=1; i <= node->edge_length && y+i < MAX_HEIGHT; i++) 
    {
      rprofile[y+i] = MAX(rprofile[y+i], x+i);
    }
  }
  compute_rprofile(node->left, x-node->edge_length-1, y+node->edge_length+1);
  compute_rprofile(node->right, x+node->edge_length+1, y+node->edge_length+1);
}
Exemplo n.º 3
0
void compute_rprofile(Pnode * pn, int x, int y)
{
    int i, notleft;

    if (pn == NULL)
        return;
    notleft = (pn->parent_dir != -1);
    rprofile[y] = max(rprofile[y], x + ((pn->lablen - notleft) / 2));
    if (pn->right != NULL) {
        for (i = 1; i <= pn->edge_length && y + i < MAX_HEIGHT; i++) {
            rprofile[y + i] = max(rprofile[y + i], x + i);
        }
    }
    compute_rprofile(pn->left, x - pn->edge_length - 1,
                     y + pn->edge_length + 1);
    compute_rprofile(pn->right, x + pn->edge_length + 1,
                     y + pn->edge_length + 1);
}
Exemplo n.º 4
0
/* 
 * This function fills in the edge_length and height fields of the
 * specified tree.
 */
void compute_edge_lengths(Pnode * pn)
{
    int h, hmin, i, delta;

    if (pn == NULL)
        return;
    compute_edge_lengths(pn->left);
    compute_edge_lengths(pn->right);

    /* first fill in the edge_length of pn */
    if (pn->right == NULL && pn->left == NULL) {
        pn->edge_length = 0;
    } else {
        if (pn->left != NULL) {
            for (i = 0; i < pn->left->height && i < MAX_HEIGHT; i++) {
                rprofile[i] = -INFINITY;
            }
            compute_rprofile(pn->left, 0, 0);
            hmin = pn->left->height;
        } else {
            hmin = 0;
        }
        if (pn->right != NULL) {
            for (i = 0; i < pn->right->height && i < MAX_HEIGHT; i++) {
                lprofile[i] = INFINITY;
            }
            compute_lprofile(pn->right, 0, 0);
            hmin = min(pn->right->height, hmin);
        } else {
            hmin = 0;
        }
        delta = 4;
        for (i = 0; i < hmin; i++) {
            delta = max(delta, 2 + 1 + rprofile[i] - lprofile[i]);
            /* the "2" guarantees a gap of 2 between different parts of the tree */
        }
        /* If the node has two children of height 1, then we allow the
           two leaves to be within 1, instead of 2 */
        if (((pn->left != NULL && pn->left->height == 1) ||
             (pn->right != NULL && pn->right->height == 1)) && delta > 4)
            delta--;
        pn->edge_length = ((delta + 1) / 2) - 1;
    }

    /* now fill in the height of pn */
    h = 1;
    if (pn->left != NULL) {
        h = max(pn->left->height + pn->edge_length + 1, h);
    }
    if (pn->right != NULL) {
        h = max(pn->right->height + pn->edge_length + 1, h);
    }
    pn->height = h;
}
Exemplo n.º 5
0
//---------------------------------------------------------
//This function fills in the edge_length and 
//height fields of the specified tree
void AsciiTree::compute_edge_lengths(AsciiNode* ascii_node) 
{
	if(ascii_node==NULL)
	       return;

	int h, hmin, delta;
	compute_edge_lengths(ascii_node->left);
	compute_edge_lengths(ascii_node->right);

	// first fill in the edge_length of node
	if(ascii_node->right==NULL && ascii_node->left==NULL) 
		ascii_node->edge_length=0;
	else 
	{
		if(ascii_node->left!=NULL) 
		{
			for(int i=0; i<ascii_node->left->height && i<MAX_HEIGHT; ++i) 
				rprofile[i]=-INFINITY;
			compute_rprofile(ascii_node->left, 0, 0);
			hmin=ascii_node->left->height;
		} 
		else 
			hmin=0;
		if(ascii_node->right!=NULL) 
		{
			for(int i=0; i<ascii_node->right->height && i<MAX_HEIGHT; ++i) 
				lprofile[i]=INFINITY;
			compute_lprofile(ascii_node->right, 0, 0);
			hmin=std::min(ascii_node->right->height, hmin);
		} 
		else 
			hmin=0;
		delta=4;
		for(int i=0; i<hmin; ++i) 
			delta=std::max(delta, gap+1+rprofile[i]-lprofile[i]);

		//If the node has two children of height 1, then we allow the
		//two leaves to be within 1, instead of 2 
		if(((ascii_node->left!=NULL && ascii_node->left->height==1)
			|| (ascii_node->right!=NULL && ascii_node->right->height==1)) && delta>4) 
			--delta;

		ascii_node->edge_length=((delta+1)/2)-1;
	}

	//now fill in the height of node
	h=1;
	if(ascii_node->left!=NULL) 
		h=std::max(ascii_node->left->height+ascii_node->edge_length+1, h);
	if(ascii_node->right!=NULL) 
		h=std::max(ascii_node->right->height+ascii_node->edge_length+1, h);
	ascii_node->height=h;
}
//This function fills in the edge_length and 
//height fields of the specified tree
void compute_edge_lengths(asciinode *node) 
{
  int h, hmin, i, delta;
  if (node == NULL) return;
  compute_edge_lengths(node->left);
  compute_edge_lengths(node->right);

  /* first fill in the edge_length of node */
  if (node->right == NULL && node->left == NULL) 
  {
    node->edge_length = 0;
  } 
  else 
  {
    if (node->left != NULL) 
    {
      for (i=0; i<node->left->height && i < MAX_HEIGHT; i++) 
      {
        rprofile[i] = -INFINITY;
      }
      compute_rprofile(node->left, 0, 0);
      hmin = node->left->height;
    } 
    else 
    {
      hmin = 0;
    }
    if (node->right != NULL) 
    {
      for (i=0; i<node->right->height && i < MAX_HEIGHT; i++) 
      {
        lprofile[i] = INFINITY;
      }
      compute_lprofile(node->right, 0, 0);
      hmin = MIN(node->right->height, hmin);
    } 
    else 
    {
      hmin = 0;
    }
    delta = 4;
    for (i=0; i<hmin; i++) 
    {
      delta = MAX(delta, gap + 1 + rprofile[i] - lprofile[i]);
    }

    //If the node has two children of height 1, then we allow the
    //two leaves to be within 1, instead of 2 
    if (((node->left != NULL && node->left->height == 1) ||
          (node->right != NULL && node->right->height == 1))&&delta>4) 
    {
      delta--;
    }

    node->edge_length = ((delta+1)/2) - 1;
  }

  //now fill in the height of node
  h = 1;
  if (node->left != NULL) 
  {
    h = MAX(node->left->height + node->edge_length + 1, h);
  }
  if (node->right != NULL) 
  {
    h = MAX(node->right->height + node->edge_length + 1, h);
  }
  node->height = h;
}