src/mtr/mtrBasic.c File Reference

#include "util.h"
#include "mtrInt.h"
Include dependency graph for mtrBasic.c:

Go to the source code of this file.

Functions

MtrNodeMtr_AllocNode (void)
void Mtr_DeallocNode (MtrNode *node)
MtrNodeMtr_InitTree (void)
void Mtr_FreeTree (MtrNode *node)
MtrNodeMtr_CopyTree (MtrNode *node, int expansion)
void Mtr_MakeFirstChild (MtrNode *parent, MtrNode *child)
void Mtr_MakeLastChild (MtrNode *parent, MtrNode *child)
MtrNodeMtr_CreateFirstChild (MtrNode *parent)
MtrNodeMtr_CreateLastChild (MtrNode *parent)
void Mtr_MakeNextSibling (MtrNode *first, MtrNode *second)
void Mtr_PrintTree (MtrNode *node)

Variables

static char rcsid[] MTR_UNUSED = "$Id: mtrBasic.c,v 1.13 2009/02/20 02:03:47 fabio Exp $"

Function Documentation

MtrNode* Mtr_AllocNode ( void   ) 

AutomaticStart AutomaticEnd Function********************************************************************

Synopsis [Allocates new tree node.]

Description [Allocates new tree node. Returns pointer to node.]

SideEffects [None]

SeeAlso [Mtr_DeallocNode]

Definition at line 117 of file mtrBasic.c.

00118 {
00119     MtrNode *node;
00120 
00121     node = ALLOC(MtrNode,1);
00122     return node;
00123 
00124 } /* Mtr_AllocNode */

MtrNode* Mtr_CopyTree ( MtrNode node,
int  expansion 
)

Function********************************************************************

Synopsis [Makes a copy of tree.]

Description [Makes a copy of tree. If parameter expansion is greater than 1, it will expand the tree by that factor. It is an error for expansion to be less than 1. Returns a pointer to the copy if successful; NULL otherwise.]

SideEffects [None]

SeeAlso [Mtr_InitTree]

Definition at line 214 of file mtrBasic.c.

00217 {
00218     MtrNode *copy;
00219 
00220     if (node == NULL) return(NULL);
00221     if (expansion < 1) return(NULL);
00222     copy = Mtr_AllocNode();
00223     if (copy == NULL) return(NULL);
00224     copy->parent = copy->elder = copy->child = copy->younger = NULL;
00225     if (node->child != NULL) {
00226         copy->child = Mtr_CopyTree(node->child, expansion);
00227         if (copy->child == NULL) {
00228             Mtr_DeallocNode(copy);
00229             return(NULL);
00230         }
00231     }
00232     if (node->younger != NULL) {
00233         copy->younger = Mtr_CopyTree(node->younger, expansion);
00234         if (copy->younger == NULL) {
00235             Mtr_FreeTree(copy);
00236             return(NULL);
00237         }
00238     }
00239     copy->flags = node->flags;
00240     copy->low = node->low * expansion;
00241     copy->size = node->size * expansion;
00242     copy->index = node->index * expansion;
00243     if (copy->younger) copy->younger->elder = copy;
00244     if (copy->child) {
00245         MtrNode *auxnode = copy->child;
00246         while (auxnode != NULL) {
00247             auxnode->parent = copy;
00248             auxnode = auxnode->younger;
00249         }
00250     }
00251     return(copy);
00252 
00253 } /* end of Mtr_CopyTree */

MtrNode* Mtr_CreateFirstChild ( MtrNode parent  ) 

Function********************************************************************

Synopsis [Creates a new node and makes it the first child of parent.]

Description [Creates a new node and makes it the first child of parent. Returns pointer to new child.]

SideEffects [None]

SeeAlso [Mtr_MakeFirstChild Mtr_CreateLastChild]

Definition at line 336 of file mtrBasic.c.

00338 {
00339     MtrNode *child;
00340 
00341     child = Mtr_AllocNode();
00342     if (child == NULL) return(NULL);
00343 
00344     child->child = child->younger = child-> elder = NULL;
00345     child->flags = 0;
00346     Mtr_MakeFirstChild(parent,child);
00347     return(child);
00348 
00349 } /* end of Mtr_CreateFirstChild */

MtrNode* Mtr_CreateLastChild ( MtrNode parent  ) 

Function********************************************************************

Synopsis [Creates a new node and makes it the last child of parent.]

Description [Creates a new node and makes it the last child of parent. Returns pointer to new child.]

SideEffects [None]

SeeAlso [Mtr_MakeLastChild Mtr_CreateFirstChild]

Definition at line 365 of file mtrBasic.c.

00367 {
00368     MtrNode *child;
00369 
00370     child = Mtr_AllocNode();
00371     if (child == NULL) return(NULL);
00372 
00373     child->child = child->younger = child->elder = NULL;
00374     child->flags = 0;
00375     Mtr_MakeLastChild(parent,child);
00376     return(child);
00377 
00378 } /* end of Mtr_CreateLastChild */

void Mtr_DeallocNode ( MtrNode node  ) 

Function********************************************************************

Synopsis [Deallocates tree node.]

Description []

SideEffects [None]

SeeAlso [Mtr_AllocNode]

Definition at line 139 of file mtrBasic.c.

00141 {
00142     FREE(node);
00143     return;
00144 
00145 } /* end of Mtr_DeallocNode */

void Mtr_FreeTree ( MtrNode node  ) 

Function********************************************************************

Synopsis [Disposes of tree rooted at node.]

Description []

SideEffects [None]

SeeAlso [Mtr_InitTree]

Definition at line 187 of file mtrBasic.c.

00189 {
00190     if (node == NULL) return;
00191     if (! MTR_TEST(node,MTR_TERMINAL)) Mtr_FreeTree(node->child);
00192     Mtr_FreeTree(node->younger);
00193     Mtr_DeallocNode(node);
00194     return;
00195 
00196 } /* end of Mtr_FreeTree */

MtrNode* Mtr_InitTree ( void   ) 

Function********************************************************************

Synopsis [Initializes tree with one node.]

Description [Initializes tree with one node. Returns pointer to node.]

SideEffects [None]

SeeAlso [Mtr_FreeTree Mtr_InitGroupTree]

Definition at line 160 of file mtrBasic.c.

00161 {
00162     MtrNode *node;
00163 
00164     node = Mtr_AllocNode();
00165     if (node == NULL) return(NULL);
00166 
00167     node->parent = node->child = node->elder = node->younger = NULL;
00168     node->flags = 0;
00169 
00170     return(node);
00171 
00172 } /* end of Mtr_InitTree */

void Mtr_MakeFirstChild ( MtrNode parent,
MtrNode child 
)

Function********************************************************************

Synopsis [Makes child the first child of parent.]

Description []

SideEffects [None]

SeeAlso [Mtr_MakeLastChild Mtr_CreateFirstChild]

Definition at line 268 of file mtrBasic.c.

00271 {
00272     child->parent = parent;
00273     child->younger = parent->child;
00274     child->elder = NULL;
00275     if (parent->child != NULL) {
00276 #ifdef MTR_DEBUG
00277         assert(parent->child->elder == NULL);
00278 #endif
00279         parent->child->elder = child;
00280     }
00281     parent->child = child;
00282     return;
00283 
00284 } /* end of Mtr_MakeFirstChild */

void Mtr_MakeLastChild ( MtrNode parent,
MtrNode child 
)

Function********************************************************************

Synopsis [Makes child the last child of parent.]

Description []

SideEffects [None]

SeeAlso [Mtr_MakeFirstChild Mtr_CreateLastChild]

Definition at line 299 of file mtrBasic.c.

00302 {
00303     MtrNode *node;
00304 
00305     child->younger = NULL;
00306 
00307     if (parent->child == NULL) {
00308         parent->child = child;
00309         child->elder = NULL;
00310     } else {
00311         for (node = parent->child;
00312              node->younger != NULL;
00313              node = node->younger);
00314         node->younger = child;
00315         child->elder = node;
00316     }
00317     child->parent = parent;
00318     return;
00319 
00320 } /* end of Mtr_MakeLastChild */

void Mtr_MakeNextSibling ( MtrNode first,
MtrNode second 
)

Function********************************************************************

Synopsis [Makes second the next sibling of first.]

Description [Makes second the next sibling of first. Second becomes a child of the parent of first.]

SideEffects [None]

SeeAlso []

Definition at line 394 of file mtrBasic.c.

00397 {
00398     second->younger = first->younger;
00399     if (first->younger != NULL) {
00400         first->younger->elder = second;
00401     }
00402     second->parent = first->parent;
00403     first->younger = second;
00404     second->elder = first;
00405     return;
00406 
00407 } /* end of Mtr_MakeNextSibling */

void Mtr_PrintTree ( MtrNode node  ) 

Function********************************************************************

Synopsis [Prints a tree, one node per line.]

Description []

SideEffects [None]

SeeAlso [Mtr_PrintGroups]

Definition at line 422 of file mtrBasic.c.

00424 {
00425     if (node == NULL) return;
00426     (void) fprintf(stdout,
00427 #if SIZEOF_VOID_P == 8
00428     "N=0x%-8lx C=0x%-8lx Y=0x%-8lx E=0x%-8lx P=0x%-8lx F=%x L=%u S=%u\n",
00429     (unsigned long) node, (unsigned long) node->child,
00430     (unsigned long) node->younger, (unsigned long) node->elder,
00431     (unsigned long) node->parent, node->flags, node->low, node->size);
00432 #else
00433     "N=0x%-8x C=0x%-8x Y=0x%-8x E=0x%-8x P=0x%-8x F=%x L=%hu S=%hu\n",
00434     (unsigned) node, (unsigned) node->child,
00435     (unsigned) node->younger, (unsigned) node->elder,
00436     (unsigned) node->parent, node->flags, node->low, node->size);
00437 #endif
00438     if (!MTR_TEST(node,MTR_TERMINAL)) Mtr_PrintTree(node->child);
00439     Mtr_PrintTree(node->younger);
00440     return;
00441 
00442 } /* end of Mtr_PrintTree */


Variable Documentation

char rcsid [] MTR_UNUSED = "$Id: mtrBasic.c,v 1.13 2009/02/20 02:03:47 fabio Exp $" [static]

CFile***********************************************************************

FileName [mtrBasic.c]

PackageName [mtr]

Synopsis [Basic manipulation of multiway branching trees.]

Description [External procedures included in this module:

]

SeeAlso [cudd package]

Author [Fabio Somenzi]

Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of the University of Colorado nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.]

Definition at line 84 of file mtrBasic.c.


Generated on Tue Jan 12 13:57:27 2010 for glu-2.2 by  doxygen 1.6.1