SVF
Functions | Variables
mtrBasic.c File Reference
#include "CUDD/util.h"
#include "CUDD/mtrInt.h"

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.15 2012/02/05 01:06:19 fabio Exp $"
 

Function Documentation

◆ Mtr_AllocNode()

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.

118 {
119  MtrNode *node;
120 
121  node = ALLOC(MtrNode,1);
122  return node;
123 
124 } /* Mtr_AllocNode */
#define ALLOC(type, num)
Definition: util.h:76
Definition: mtr.h:126

◆ Mtr_CopyTree()

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.

217 {
218  MtrNode *copy;
219 
220  if (node == NULL) return(NULL);
221  if (expansion < 1) return(NULL);
222  copy = Mtr_AllocNode();
223  if (copy == NULL) return(NULL);
224  copy->parent = copy->elder = copy->child = copy->younger = NULL;
225  if (node->child != NULL) {
226  copy->child = Mtr_CopyTree(node->child, expansion);
227  if (copy->child == NULL) {
228  Mtr_DeallocNode(copy);
229  return(NULL);
230  }
231  }
232  if (node->younger != NULL) {
233  copy->younger = Mtr_CopyTree(node->younger, expansion);
234  if (copy->younger == NULL) {
235  Mtr_FreeTree(copy);
236  return(NULL);
237  }
238  }
239  copy->flags = node->flags;
240  copy->low = node->low * expansion;
241  copy->size = node->size * expansion;
242  copy->index = node->index * expansion;
243  if (copy->younger) copy->younger->elder = copy;
244  if (copy->child) {
245  MtrNode *auxnode = copy->child;
246  while (auxnode != NULL) {
247  auxnode->parent = copy;
248  auxnode = auxnode->younger;
249  }
250  }
251  return(copy);
252 
253 } /* end of Mtr_CopyTree */
MtrHalfWord flags
Definition: mtr.h:127
MtrHalfWord size
Definition: mtr.h:129
MtrNode * Mtr_CopyTree(MtrNode *node, int expansion)
Definition: mtrBasic.c:214
struct MtrNode * parent
Definition: mtr.h:131
struct MtrNode * elder
Definition: mtr.h:133
struct MtrNode * younger
Definition: mtr.h:134
void Mtr_DeallocNode(MtrNode *node)
Definition: mtrBasic.c:139
MtrHalfWord index
Definition: mtr.h:130
MtrNode * Mtr_AllocNode(void)
Definition: mtrBasic.c:117
MtrHalfWord low
Definition: mtr.h:128
Definition: mtr.h:126
void Mtr_FreeTree(MtrNode *node)
Definition: mtrBasic.c:187
struct MtrNode * child
Definition: mtr.h:132

◆ Mtr_CreateFirstChild()

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.

338 {
339  MtrNode *child;
340 
341  child = Mtr_AllocNode();
342  if (child == NULL) return(NULL);
343 
344  child->child = NULL;
345  child->flags = 0;
346  Mtr_MakeFirstChild(parent,child);
347  return(child);
348 
349 } /* end of Mtr_CreateFirstChild */
MtrHalfWord flags
Definition: mtr.h:127
MtrNode * Mtr_AllocNode(void)
Definition: mtrBasic.c:117
Definition: mtr.h:126
void Mtr_MakeFirstChild(MtrNode *parent, MtrNode *child)
Definition: mtrBasic.c:268
struct MtrNode * child
Definition: mtr.h:132

◆ Mtr_CreateLastChild()

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.

367 {
368  MtrNode *child;
369 
370  child = Mtr_AllocNode();
371  if (child == NULL) return(NULL);
372 
373  child->child = NULL;
374  child->flags = 0;
375  Mtr_MakeLastChild(parent,child);
376  return(child);
377 
378 } /* end of Mtr_CreateLastChild */
MtrHalfWord flags
Definition: mtr.h:127
void Mtr_MakeLastChild(MtrNode *parent, MtrNode *child)
Definition: mtrBasic.c:299
MtrNode * Mtr_AllocNode(void)
Definition: mtrBasic.c:117
Definition: mtr.h:126
struct MtrNode * child
Definition: mtr.h:132

◆ Mtr_DeallocNode()

void Mtr_DeallocNode ( MtrNode node)

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

Synopsis [Deallocates tree node.]

Description []

SideEffects [None]

SeeAlso [Mtr_AllocNode]

Definition at line 139 of file mtrBasic.c.

141 {
142  FREE(node);
143  return;
144 
145 } /* end of Mtr_DeallocNode */
#define FREE(obj)
Definition: util.h:80

◆ Mtr_FreeTree()

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.

189 {
190  if (node == NULL) return;
191  if (! MTR_TEST(node,MTR_TERMINAL)) Mtr_FreeTree(node->child);
192  Mtr_FreeTree(node->younger);
193  Mtr_DeallocNode(node);
194  return;
195 
196 } /* end of Mtr_FreeTree */
#define MTR_TERMINAL
Definition: mtr.h:95
#define MTR_TEST(node, flag)
Definition: mtr.h:150
struct MtrNode * younger
Definition: mtr.h:134
void Mtr_DeallocNode(MtrNode *node)
Definition: mtrBasic.c:139
void Mtr_FreeTree(MtrNode *node)
Definition: mtrBasic.c:187
struct MtrNode * child
Definition: mtr.h:132

◆ Mtr_InitTree()

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.

161 {
162  MtrNode *node;
163 
164  node = Mtr_AllocNode();
165  if (node == NULL) return(NULL);
166 
167  node->parent = node->child = node->elder = node->younger = NULL;
168  node->flags = 0;
169 
170  return(node);
171 
172 } /* end of Mtr_InitTree */
MtrHalfWord flags
Definition: mtr.h:127
struct MtrNode * parent
Definition: mtr.h:131
struct MtrNode * elder
Definition: mtr.h:133
struct MtrNode * younger
Definition: mtr.h:134
MtrNode * Mtr_AllocNode(void)
Definition: mtrBasic.c:117
Definition: mtr.h:126
struct MtrNode * child
Definition: mtr.h:132

◆ Mtr_MakeFirstChild()

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.

271 {
272  child->parent = parent;
273  child->younger = parent->child;
274  child->elder = NULL;
275  if (parent->child != NULL) {
276 #ifdef MTR_DEBUG
277  assert(parent->child->elder == NULL);
278 #endif
279  parent->child->elder = child;
280  }
281  parent->child = child;
282  return;
283 
284 } /* end of Mtr_MakeFirstChild */
#define assert(ex)
Definition: util.h:141
struct MtrNode * parent
Definition: mtr.h:131
struct MtrNode * elder
Definition: mtr.h:133
struct MtrNode * younger
Definition: mtr.h:134
struct MtrNode * child
Definition: mtr.h:132

◆ Mtr_MakeLastChild()

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.

302 {
303  MtrNode *node;
304 
305  child->younger = NULL;
306 
307  if (parent->child == NULL) {
308  parent->child = child;
309  child->elder = NULL;
310  } else {
311  for (node = parent->child;
312  node->younger != NULL;
313  node = node->younger);
314  node->younger = child;
315  child->elder = node;
316  }
317  child->parent = parent;
318  return;
319 
320 } /* end of Mtr_MakeLastChild */
struct MtrNode * parent
Definition: mtr.h:131
struct MtrNode * elder
Definition: mtr.h:133
struct MtrNode * younger
Definition: mtr.h:134
Definition: mtr.h:126
struct MtrNode * child
Definition: mtr.h:132

◆ Mtr_MakeNextSibling()

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.

397 {
398  second->parent = first->parent;
399  second->elder = first;
400  second->younger = first->younger;
401  if (first->younger != NULL) {
402  first->younger->elder = second;
403  }
404  first->younger = second;
405  return;
406 
407 } /* end of Mtr_MakeNextSibling */
struct MtrNode * parent
Definition: mtr.h:131
struct MtrNode * elder
Definition: mtr.h:133
struct MtrNode * younger
Definition: mtr.h:134

◆ Mtr_PrintTree()

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.

424 {
425  if (node == NULL) return;
426  (void) fprintf(stdout,
427 #if SIZEOF_VOID_P == 8
428  "N=0x%-8lx C=0x%-8lx Y=0x%-8lx E=0x%-8lx P=0x%-8lx F=%x L=%u S=%u\n",
429  (unsigned long) node, (unsigned long) node->child,
430  (unsigned long) node->younger, (unsigned long) node->elder,
431  (unsigned long) node->parent, node->flags, node->low, node->size);
432 #else
433  "N=0x%-8x C=0x%-8x Y=0x%-8x E=0x%-8x P=0x%-8x F=%x L=%hu S=%hu\n",
434  (unsigned) node, (unsigned) node->child,
435  (unsigned) node->younger, (unsigned) node->elder,
436  (unsigned) node->parent, node->flags, node->low, node->size);
437 #endif
438  if (!MTR_TEST(node,MTR_TERMINAL)) Mtr_PrintTree(node->child);
439  Mtr_PrintTree(node->younger);
440  return;
441 
442 } /* end of Mtr_PrintTree */
void Mtr_PrintTree(MtrNode *node)
Definition: mtrBasic.c:422
#define MTR_TERMINAL
Definition: mtr.h:95
MtrHalfWord flags
Definition: mtr.h:127
MtrHalfWord size
Definition: mtr.h:129
struct MtrNode * parent
Definition: mtr.h:131
struct MtrNode * elder
Definition: mtr.h:133
#define MTR_TEST(node, flag)
Definition: mtr.h:150
struct MtrNode * younger
Definition: mtr.h:134
MtrHalfWord low
Definition: mtr.h:128
#define SIZEOF_VOID_P
Definition: mtr.h:75
struct MtrNode * child
Definition: mtr.h:132

Variable Documentation

◆ MTR_UNUSED

char rcsid [] MTR_UNUSED = "$Id: mtrBasic.c,v 1.15 2012/02/05 01:06:19 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-2012, 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.