abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mtrBasic.c File Reference
#include "misc/util/util_hack.h"
#include "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
ABC_NAMESPACE_IMPL_START 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 118 of file mtrBasic.c.

119 {
120  MtrNode *node;
121 
122  node = ABC_ALLOC(MtrNode,1);
123  return node;
124 
125 } /* Mtr_AllocNode */
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Definition: mtr.h:131
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 215 of file mtrBasic.c.

218 {
219  MtrNode *copy;
220 
221  if (node == NULL) return(NULL);
222  if (expansion < 1) return(NULL);
223  copy = Mtr_AllocNode();
224  if (copy == NULL) return(NULL);
225  copy->parent = copy->elder = copy->child = copy->younger = NULL;
226  if (node->child != NULL) {
227  copy->child = Mtr_CopyTree(node->child, expansion);
228  if (copy->child == NULL) {
229  Mtr_DeallocNode(copy);
230  return(NULL);
231  }
232  }
233  if (node->younger != NULL) {
234  copy->younger = Mtr_CopyTree(node->younger, expansion);
235  if (copy->younger == NULL) {
236  Mtr_FreeTree(copy);
237  return(NULL);
238  }
239  }
240  copy->flags = node->flags;
241  copy->low = node->low * expansion;
242  copy->size = node->size * expansion;
243  copy->index = node->index * expansion;
244  if (copy->younger) copy->younger->elder = copy;
245  if (copy->child) {
246  MtrNode *auxnode = copy->child;
247  while (auxnode != NULL) {
248  auxnode->parent = copy;
249  auxnode = auxnode->younger;
250  }
251  }
252  return(copy);
253 
254 } /* end of Mtr_CopyTree */
MtrHalfWord flags
Definition: mtr.h:132
static void copy(const T &from, T &to)
Definition: Alg.h:61
MtrHalfWord size
Definition: mtr.h:134
MtrNode * Mtr_CopyTree(MtrNode *node, int expansion)
Definition: mtrBasic.c:215
struct MtrNode * parent
Definition: mtr.h:136
struct MtrNode * elder
Definition: mtr.h:138
struct MtrNode * younger
Definition: mtr.h:139
void Mtr_DeallocNode(MtrNode *node)
Definition: mtrBasic.c:140
MtrHalfWord index
Definition: mtr.h:135
MtrNode * Mtr_AllocNode(void)
Definition: mtrBasic.c:118
MtrHalfWord low
Definition: mtr.h:133
Definition: mtr.h:131
void Mtr_FreeTree(MtrNode *node)
Definition: mtrBasic.c:188
struct MtrNode * child
Definition: mtr.h:137
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 337 of file mtrBasic.c.

339 {
340  MtrNode *child;
341 
342  child = Mtr_AllocNode();
343  if (child == NULL) return(NULL);
344 
345  child->child = child->younger = child-> elder = NULL;
346  child->flags = 0;
347  Mtr_MakeFirstChild(parent,child);
348  return(child);
349 
350 } /* end of Mtr_CreateFirstChild */
MtrHalfWord flags
Definition: mtr.h:132
struct MtrNode * younger
Definition: mtr.h:139
MtrNode * Mtr_AllocNode(void)
Definition: mtrBasic.c:118
Definition: mtr.h:131
void Mtr_MakeFirstChild(MtrNode *parent, MtrNode *child)
Definition: mtrBasic.c:269
struct MtrNode * child
Definition: mtr.h:137
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 366 of file mtrBasic.c.

368 {
369  MtrNode *child;
370 
371  child = Mtr_AllocNode();
372  if (child == NULL) return(NULL);
373 
374  child->child = child->younger = child->elder = NULL;
375  child->flags = 0;
376  Mtr_MakeLastChild(parent,child);
377  return(child);
378 
379 } /* end of Mtr_CreateLastChild */
MtrHalfWord flags
Definition: mtr.h:132
struct MtrNode * elder
Definition: mtr.h:138
void Mtr_MakeLastChild(MtrNode *parent, MtrNode *child)
Definition: mtrBasic.c:300
struct MtrNode * younger
Definition: mtr.h:139
MtrNode * Mtr_AllocNode(void)
Definition: mtrBasic.c:118
Definition: mtr.h:131
struct MtrNode * child
Definition: mtr.h:137
void Mtr_DeallocNode ( MtrNode node)

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

Synopsis [Deallocates tree node.]

Description []

SideEffects [None]

SeeAlso [Mtr_AllocNode]

Definition at line 140 of file mtrBasic.c.

142 {
143  ABC_FREE(node);
144  return;
145 
146 } /* end of Mtr_DeallocNode */
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Mtr_FreeTree ( MtrNode node)

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

Synopsis [Disposes of tree rooted at node.]

Description []

SideEffects [None]

SeeAlso [Mtr_InitTree]

Definition at line 188 of file mtrBasic.c.

190 {
191  if (node == NULL) return;
192  if (! MTR_TEST(node,MTR_TERMINAL)) Mtr_FreeTree(node->child);
193  Mtr_FreeTree(node->younger);
194  Mtr_DeallocNode(node);
195  return;
196 
197 } /* end of Mtr_FreeTree */
#define MTR_TERMINAL
Definition: mtr.h:100
#define MTR_TEST(node, flag)
Definition: mtr.h:155
struct MtrNode * younger
Definition: mtr.h:139
void Mtr_DeallocNode(MtrNode *node)
Definition: mtrBasic.c:140
void Mtr_FreeTree(MtrNode *node)
Definition: mtrBasic.c:188
struct MtrNode * child
Definition: mtr.h:137
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 161 of file mtrBasic.c.

162 {
163  MtrNode *node;
164 
165  node = Mtr_AllocNode();
166  if (node == NULL) return(NULL);
167 
168  node->parent = node->child = node->elder = node->younger = NULL;
169  node->flags = 0;
170 
171  return(node);
172 
173 } /* end of Mtr_InitTree */
MtrHalfWord flags
Definition: mtr.h:132
struct MtrNode * parent
Definition: mtr.h:136
struct MtrNode * elder
Definition: mtr.h:138
struct MtrNode * younger
Definition: mtr.h:139
MtrNode * Mtr_AllocNode(void)
Definition: mtrBasic.c:118
Definition: mtr.h:131
struct MtrNode * child
Definition: mtr.h:137
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 269 of file mtrBasic.c.

272 {
273  child->parent = parent;
274  child->younger = parent->child;
275  child->elder = NULL;
276  if (parent->child != NULL) {
277 #ifdef MTR_DEBUG
278  assert(parent->child->elder == NULL);
279 #endif
280  parent->child->elder = child;
281  }
282  parent->child = child;
283  return;
284 
285 } /* end of Mtr_MakeFirstChild */
struct MtrNode * parent
Definition: mtr.h:136
struct MtrNode * elder
Definition: mtr.h:138
struct MtrNode * younger
Definition: mtr.h:139
#define assert(ex)
Definition: util_old.h:213
struct MtrNode * child
Definition: mtr.h:137
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 300 of file mtrBasic.c.

303 {
304  MtrNode *node;
305 
306  child->younger = NULL;
307 
308  if (parent->child == NULL) {
309  parent->child = child;
310  child->elder = NULL;
311  } else {
312  for (node = parent->child;
313  node->younger != NULL;
314  node = node->younger);
315  node->younger = child;
316  child->elder = node;
317  }
318  child->parent = parent;
319  return;
320 
321 } /* end of Mtr_MakeLastChild */
struct MtrNode * parent
Definition: mtr.h:136
struct MtrNode * elder
Definition: mtr.h:138
struct MtrNode * younger
Definition: mtr.h:139
Definition: mtr.h:131
struct MtrNode * child
Definition: mtr.h:137
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 395 of file mtrBasic.c.

398 {
399  second->younger = first->younger;
400  if (first->younger != NULL) {
401  first->younger->elder = second;
402  }
403  second->parent = first->parent;
404  first->younger = second;
405  second->elder = first;
406  return;
407 
408 } /* end of Mtr_MakeNextSibling */
struct MtrNode * parent
Definition: mtr.h:136
struct MtrNode * elder
Definition: mtr.h:138
struct MtrNode * younger
Definition: mtr.h:139
void Mtr_PrintTree ( MtrNode node)

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

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

Description []

SideEffects [None]

SeeAlso [Mtr_PrintGroups]

Definition at line 423 of file mtrBasic.c.

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

Variable Documentation

ABC_NAMESPACE_IMPL_START 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 85 of file mtrBasic.c.