abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fxuHeapS.c File Reference
#include "fxuInt.h"

Go to the source code of this file.

Macros

#define FXU_HEAP_SINGLE_WEIGHT(pSingle)   ((pSingle)->Weight)
 DECLARATIONS ///. More...
 
#define FXU_HEAP_SINGLE_CURRENT(p, pSingle)   ((p)->pTree[(pSingle)->HNum])
 
#define FXU_HEAP_SINGLE_PARENT_EXISTS(p, pSingle)   ((pSingle)->HNum > 1)
 
#define FXU_HEAP_SINGLE_CHILD1_EXISTS(p, pSingle)   (((pSingle)->HNum << 1) <= p->nItems)
 
#define FXU_HEAP_SINGLE_CHILD2_EXISTS(p, pSingle)   ((((pSingle)->HNum << 1)+1) <= p->nItems)
 
#define FXU_HEAP_SINGLE_PARENT(p, pSingle)   ((p)->pTree[(pSingle)->HNum >> 1])
 
#define FXU_HEAP_SINGLE_CHILD1(p, pSingle)   ((p)->pTree[(pSingle)->HNum << 1])
 
#define FXU_HEAP_SINGLE_CHILD2(p, pSingle)   ((p)->pTree[((pSingle)->HNum << 1)+1])
 
#define FXU_HEAP_SINGLE_ASSERT(p, pSingle)   assert( (pSingle)->HNum >= 1 && (pSingle)->HNum <= p->nItemsAlloc )
 

Functions

static void Fxu_HeapSingleResize (Fxu_HeapSingle *p)
 
static void Fxu_HeapSingleSwap (Fxu_Single **pSingle1, Fxu_Single **pSingle2)
 
static void Fxu_HeapSingleMoveUp (Fxu_HeapSingle *p, Fxu_Single *pSingle)
 
static void Fxu_HeapSingleMoveDn (Fxu_HeapSingle *p, Fxu_Single *pSingle)
 
Fxu_HeapSingleFxu_HeapSingleStart ()
 FUNCTION DEFINITIONS ///. More...
 
void Fxu_HeapSingleStop (Fxu_HeapSingle *p)
 
void Fxu_HeapSinglePrint (FILE *pFile, Fxu_HeapSingle *p)
 
void Fxu_HeapSingleCheck (Fxu_HeapSingle *p)
 
void Fxu_HeapSingleCheckOne (Fxu_HeapSingle *p, Fxu_Single *pSingle)
 
void Fxu_HeapSingleInsert (Fxu_HeapSingle *p, Fxu_Single *pSingle)
 
void Fxu_HeapSingleUpdate (Fxu_HeapSingle *p, Fxu_Single *pSingle)
 
void Fxu_HeapSingleDelete (Fxu_HeapSingle *p, Fxu_Single *pSingle)
 
Fxu_SingleFxu_HeapSingleReadMax (Fxu_HeapSingle *p)
 
Fxu_SingleFxu_HeapSingleGetMax (Fxu_HeapSingle *p)
 
int Fxu_HeapSingleReadMaxWeight (Fxu_HeapSingle *p)
 

Macro Definition Documentation

#define FXU_HEAP_SINGLE_ASSERT (   p,
  pSingle 
)    assert( (pSingle)->HNum >= 1 && (pSingle)->HNum <= p->nItemsAlloc )

Definition at line 36 of file fxuHeapS.c.

#define FXU_HEAP_SINGLE_CHILD1 (   p,
  pSingle 
)    ((p)->pTree[(pSingle)->HNum << 1])

Definition at line 34 of file fxuHeapS.c.

#define FXU_HEAP_SINGLE_CHILD1_EXISTS (   p,
  pSingle 
)    (((pSingle)->HNum << 1) <= p->nItems)

Definition at line 31 of file fxuHeapS.c.

#define FXU_HEAP_SINGLE_CHILD2 (   p,
  pSingle 
)    ((p)->pTree[((pSingle)->HNum << 1)+1])

Definition at line 35 of file fxuHeapS.c.

#define FXU_HEAP_SINGLE_CHILD2_EXISTS (   p,
  pSingle 
)    ((((pSingle)->HNum << 1)+1) <= p->nItems)

Definition at line 32 of file fxuHeapS.c.

#define FXU_HEAP_SINGLE_CURRENT (   p,
  pSingle 
)    ((p)->pTree[(pSingle)->HNum])

Definition at line 29 of file fxuHeapS.c.

#define FXU_HEAP_SINGLE_PARENT (   p,
  pSingle 
)    ((p)->pTree[(pSingle)->HNum >> 1])

Definition at line 33 of file fxuHeapS.c.

#define FXU_HEAP_SINGLE_PARENT_EXISTS (   p,
  pSingle 
)    ((pSingle)->HNum > 1)

Definition at line 30 of file fxuHeapS.c.

#define FXU_HEAP_SINGLE_WEIGHT (   pSingle)    ((pSingle)->Weight)

DECLARATIONS ///.

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

FileName [fxuHeapS.c]

PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]

Synopsis [The priority queue for variables.]

Author [MVSIS Group]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - February 1, 2003.]

Revision [

Id:
fxuHeapS.c,v 1.0 2003/02/01 00:00:00 alanmi Exp

]

Definition at line 28 of file fxuHeapS.c.

Function Documentation

void Fxu_HeapSingleCheck ( Fxu_HeapSingle p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 155 of file fxuHeapS.c.

156 {
157  Fxu_Single * pSingle;
158  Fxu_HeapSingleForEachItem( p, pSingle )
159  {
160  assert( pSingle->HNum == p->i );
161  Fxu_HeapSingleCheckOne( p, pSingle );
162  }
163 }
int HNum
Definition: fxuInt.h:270
#define Fxu_HeapSingleForEachItem(Heap, Single)
Definition: fxuInt.h:379
void Fxu_HeapSingleCheckOne(Fxu_HeapSingle *p, Fxu_Single *pSingle)
Definition: fxuHeapS.c:176
#define assert(ex)
Definition: util_old.h:213
void Fxu_HeapSingleCheckOne ( Fxu_HeapSingle p,
Fxu_Single pSingle 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 176 of file fxuHeapS.c.

177 {
178  int Weight1, Weight2;
179  if ( FXU_HEAP_SINGLE_CHILD1_EXISTS(p,pSingle) )
180  {
181  Weight1 = FXU_HEAP_SINGLE_WEIGHT(pSingle);
182  Weight2 = FXU_HEAP_SINGLE_WEIGHT( FXU_HEAP_SINGLE_CHILD1(p,pSingle) );
183  assert( Weight1 >= Weight2 );
184  }
185  if ( FXU_HEAP_SINGLE_CHILD2_EXISTS(p,pSingle) )
186  {
187  Weight1 = FXU_HEAP_SINGLE_WEIGHT(pSingle);
188  Weight2 = FXU_HEAP_SINGLE_WEIGHT( FXU_HEAP_SINGLE_CHILD2(p,pSingle) );
189  assert( Weight1 >= Weight2 );
190  }
191 }
#define FXU_HEAP_SINGLE_CHILD2_EXISTS(p, pSingle)
Definition: fxuHeapS.c:32
#define FXU_HEAP_SINGLE_CHILD1_EXISTS(p, pSingle)
Definition: fxuHeapS.c:31
#define FXU_HEAP_SINGLE_WEIGHT(pSingle)
DECLARATIONS ///.
Definition: fxuHeapS.c:28
#define FXU_HEAP_SINGLE_CHILD1(p, pSingle)
Definition: fxuHeapS.c:34
#define assert(ex)
Definition: util_old.h:213
#define FXU_HEAP_SINGLE_CHILD2(p, pSingle)
Definition: fxuHeapS.c:35
void Fxu_HeapSingleDelete ( Fxu_HeapSingle p,
Fxu_Single pSingle 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 251 of file fxuHeapS.c.

252 {
253  int Place = pSingle->HNum;
254  FXU_HEAP_SINGLE_ASSERT(p,pSingle);
255  // put the last entry to the deleted place
256  // decrement the number of entries
257  p->pTree[Place] = p->pTree[p->nItems--];
258  p->pTree[Place]->HNum = Place;
259  // move the top entry down if necessary
260  Fxu_HeapSingleUpdate( p, p->pTree[Place] );
261  pSingle->HNum = 0;
262 }
int HNum
Definition: fxuInt.h:270
Fxu_Single ** pTree
Definition: fxuInt.h:153
void Fxu_HeapSingleUpdate(Fxu_HeapSingle *p, Fxu_Single *pSingle)
Definition: fxuHeapS.c:226
#define FXU_HEAP_SINGLE_ASSERT(p, pSingle)
Definition: fxuHeapS.c:36
int nItems
Definition: fxuInt.h:154
Fxu_Single* Fxu_HeapSingleGetMax ( Fxu_HeapSingle p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 293 of file fxuHeapS.c.

294 {
295  Fxu_Single * pSingle;
296  if ( p->nItems == 0 )
297  return NULL;
298  // prepare the return value
299  pSingle = p->pTree[1];
300  pSingle->HNum = 0;
301  // put the last entry on top
302  // decrement the number of entries
303  p->pTree[1] = p->pTree[p->nItems--];
304  p->pTree[1]->HNum = 1;
305  // move the top entry down if necessary
306  Fxu_HeapSingleMoveDn( p, p->pTree[1] );
307  return pSingle;
308 }
int HNum
Definition: fxuInt.h:270
static void Fxu_HeapSingleMoveDn(Fxu_HeapSingle *p, Fxu_Single *pSingle)
Definition: fxuHeapS.c:392
Fxu_Single ** pTree
Definition: fxuInt.h:153
int nItems
Definition: fxuInt.h:154
void Fxu_HeapSingleInsert ( Fxu_HeapSingle p,
Fxu_Single pSingle 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 204 of file fxuHeapS.c.

205 {
206  if ( p->nItems == p->nItemsAlloc )
208  // put the last entry to the last place and move up
209  p->pTree[++p->nItems] = pSingle;
210  pSingle->HNum = p->nItems;
211  // move the last entry up if necessary
212  Fxu_HeapSingleMoveUp( p, pSingle );
213 }
static void Fxu_HeapSingleMoveUp(Fxu_HeapSingle *p, Fxu_Single *pSingle)
Definition: fxuHeapS.c:364
int HNum
Definition: fxuInt.h:270
Fxu_Single ** pTree
Definition: fxuInt.h:153
static void Fxu_HeapSingleResize(Fxu_HeapSingle *p)
Definition: fxuHeapS.c:82
int nItemsAlloc
Definition: fxuInt.h:155
int nItems
Definition: fxuInt.h:154
void Fxu_HeapSingleMoveDn ( Fxu_HeapSingle p,
Fxu_Single pSingle 
)
static

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 392 of file fxuHeapS.c.

393 {
394  Fxu_Single ** ppChild1, ** ppChild2, ** ppSingle;
395  ppSingle = &FXU_HEAP_SINGLE_CURRENT(p, pSingle);
396  while ( FXU_HEAP_SINGLE_CHILD1_EXISTS(p,*ppSingle) )
397  { // if Child1 does not exist, Child2 also does not exists
398 
399  // get the children
400  ppChild1 = &FXU_HEAP_SINGLE_CHILD1(p,*ppSingle);
401  if ( FXU_HEAP_SINGLE_CHILD2_EXISTS(p,*ppSingle) )
402  {
403  ppChild2 = &FXU_HEAP_SINGLE_CHILD2(p,*ppSingle);
404 
405  // consider two cases
406  if ( FXU_HEAP_SINGLE_WEIGHT(*ppSingle) >= FXU_HEAP_SINGLE_WEIGHT(*ppChild1) &&
407  FXU_HEAP_SINGLE_WEIGHT(*ppSingle) >= FXU_HEAP_SINGLE_WEIGHT(*ppChild2) )
408  { // Var is larger than both, skip
409  break;
410  }
411  else
412  { // Var is smaller than one of them, then swap it with larger
413  if ( FXU_HEAP_SINGLE_WEIGHT(*ppChild1) >= FXU_HEAP_SINGLE_WEIGHT(*ppChild2) )
414  {
415  Fxu_HeapSingleSwap( ppSingle, ppChild1 );
416  // update the pointer
417  ppSingle = ppChild1;
418  }
419  else
420  {
421  Fxu_HeapSingleSwap( ppSingle, ppChild2 );
422  // update the pointer
423  ppSingle = ppChild2;
424  }
425  }
426  }
427  else // Child2 does not exist
428  {
429  // consider two cases
430  if ( FXU_HEAP_SINGLE_WEIGHT(*ppSingle) >= FXU_HEAP_SINGLE_WEIGHT(*ppChild1) )
431  { // Var is larger than Child1, skip
432  break;
433  }
434  else
435  { // Var is smaller than Child1, then swap them
436  Fxu_HeapSingleSwap( ppSingle, ppChild1 );
437  // update the pointer
438  ppSingle = ppChild1;
439  }
440  }
441  }
442 }
#define FXU_HEAP_SINGLE_CHILD2_EXISTS(p, pSingle)
Definition: fxuHeapS.c:32
#define FXU_HEAP_SINGLE_CURRENT(p, pSingle)
Definition: fxuHeapS.c:29
#define FXU_HEAP_SINGLE_CHILD1_EXISTS(p, pSingle)
Definition: fxuHeapS.c:31
#define FXU_HEAP_SINGLE_WEIGHT(pSingle)
DECLARATIONS ///.
Definition: fxuHeapS.c:28
static void Fxu_HeapSingleSwap(Fxu_Single **pSingle1, Fxu_Single **pSingle2)
Definition: fxuHeapS.c:341
#define FXU_HEAP_SINGLE_CHILD1(p, pSingle)
Definition: fxuHeapS.c:34
#define FXU_HEAP_SINGLE_CHILD2(p, pSingle)
Definition: fxuHeapS.c:35
void Fxu_HeapSingleMoveUp ( Fxu_HeapSingle p,
Fxu_Single pSingle 
)
static

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 364 of file fxuHeapS.c.

365 {
366  Fxu_Single ** ppSingle, ** ppPar;
367  ppSingle = &FXU_HEAP_SINGLE_CURRENT(p, pSingle);
368  while ( FXU_HEAP_SINGLE_PARENT_EXISTS(p,*ppSingle) )
369  {
370  ppPar = &FXU_HEAP_SINGLE_PARENT(p,*ppSingle);
371  if ( FXU_HEAP_SINGLE_WEIGHT(*ppSingle) > FXU_HEAP_SINGLE_WEIGHT(*ppPar) )
372  {
373  Fxu_HeapSingleSwap( ppSingle, ppPar );
374  ppSingle = ppPar;
375  }
376  else
377  break;
378  }
379 }
#define FXU_HEAP_SINGLE_PARENT(p, pSingle)
Definition: fxuHeapS.c:33
#define FXU_HEAP_SINGLE_CURRENT(p, pSingle)
Definition: fxuHeapS.c:29
#define FXU_HEAP_SINGLE_WEIGHT(pSingle)
DECLARATIONS ///.
Definition: fxuHeapS.c:28
#define FXU_HEAP_SINGLE_PARENT_EXISTS(p, pSingle)
Definition: fxuHeapS.c:30
static void Fxu_HeapSingleSwap(Fxu_Single **pSingle1, Fxu_Single **pSingle2)
Definition: fxuHeapS.c:341
void Fxu_HeapSinglePrint ( FILE *  pFile,
Fxu_HeapSingle p 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 120 of file fxuHeapS.c.

121 {
122  Fxu_Single * pSingle;
123  int Counter = 1;
124  int Degree = 1;
125 
126  Fxu_HeapSingleCheck( p );
127  fprintf( pFile, "The contents of the heap:\n" );
128  fprintf( pFile, "Level %d: ", Degree );
129  Fxu_HeapSingleForEachItem( p, pSingle )
130  {
131  assert( Counter == p->pTree[Counter]->HNum );
132  fprintf( pFile, "%2d=%3d ", Counter, FXU_HEAP_SINGLE_WEIGHT(p->pTree[Counter]) );
133  if ( ++Counter == (1 << Degree) )
134  {
135  fprintf( pFile, "\n" );
136  Degree++;
137  fprintf( pFile, "Level %d: ", Degree );
138  }
139  }
140  fprintf( pFile, "\n" );
141  fprintf( pFile, "End of the heap printout.\n" );
142 }
void Fxu_HeapSingleCheck(Fxu_HeapSingle *p)
Definition: fxuHeapS.c:155
int HNum
Definition: fxuInt.h:270
Fxu_Single ** pTree
Definition: fxuInt.h:153
#define FXU_HEAP_SINGLE_WEIGHT(pSingle)
DECLARATIONS ///.
Definition: fxuHeapS.c:28
#define Fxu_HeapSingleForEachItem(Heap, Single)
Definition: fxuInt.h:379
static int Counter
#define assert(ex)
Definition: util_old.h:213
Fxu_Single* Fxu_HeapSingleReadMax ( Fxu_HeapSingle p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 275 of file fxuHeapS.c.

276 {
277  if ( p->nItems == 0 )
278  return NULL;
279  return p->pTree[1];
280 }
Fxu_Single ** pTree
Definition: fxuInt.h:153
int nItems
Definition: fxuInt.h:154
int Fxu_HeapSingleReadMaxWeight ( Fxu_HeapSingle p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 321 of file fxuHeapS.c.

322 {
323  if ( p->nItems == 0 )
324  return -1;
325  return FXU_HEAP_SINGLE_WEIGHT(p->pTree[1]);
326 }
Fxu_Single ** pTree
Definition: fxuInt.h:153
#define FXU_HEAP_SINGLE_WEIGHT(pSingle)
DECLARATIONS ///.
Definition: fxuHeapS.c:28
int nItems
Definition: fxuInt.h:154
void Fxu_HeapSingleResize ( Fxu_HeapSingle p)
static

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 82 of file fxuHeapS.c.

83 {
84  p->nItemsAlloc *= 2;
85  p->pTree = ABC_REALLOC( Fxu_Single *, p->pTree, p->nItemsAlloc + 10 );
86 }
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
Fxu_Single ** pTree
Definition: fxuInt.h:153
int nItemsAlloc
Definition: fxuInt.h:155
Fxu_HeapSingle* Fxu_HeapSingleStart ( )

FUNCTION DEFINITIONS ///.

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 58 of file fxuHeapS.c.

59 {
60  Fxu_HeapSingle * p;
61  p = ABC_ALLOC( Fxu_HeapSingle, 1 );
62  memset( p, 0, sizeof(Fxu_HeapSingle) );
63  p->nItems = 0;
64  p->nItemsAlloc = 2000;
65  p->pTree = ABC_ALLOC( Fxu_Single *, p->nItemsAlloc + 10 );
66  p->pTree[0] = NULL;
67  return p;
68 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Fxu_Single ** pTree
Definition: fxuInt.h:153
int nItemsAlloc
Definition: fxuInt.h:155
int nItems
Definition: fxuInt.h:154
void Fxu_HeapSingleStop ( Fxu_HeapSingle p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 99 of file fxuHeapS.c.

100 {
101  int i;
102  i = 0;
103  ABC_FREE( p->pTree );
104  i = 1;
105  ABC_FREE( p );
106 }
Fxu_Single ** pTree
Definition: fxuInt.h:153
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Fxu_HeapSingleSwap ( Fxu_Single **  pSingle1,
Fxu_Single **  pSingle2 
)
static

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 341 of file fxuHeapS.c.

342 {
343  Fxu_Single * pSingle;
344  int Temp;
345  pSingle = *pSingle1;
346  *pSingle1 = *pSingle2;
347  *pSingle2 = pSingle;
348  Temp = (*pSingle1)->HNum;
349  (*pSingle1)->HNum = (*pSingle2)->HNum;
350  (*pSingle2)->HNum = Temp;
351 }
int HNum
Definition: fxuInt.h:270
void Fxu_HeapSingleUpdate ( Fxu_HeapSingle p,
Fxu_Single pSingle 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 226 of file fxuHeapS.c.

227 {
228  FXU_HEAP_SINGLE_ASSERT(p,pSingle);
229  if ( FXU_HEAP_SINGLE_PARENT_EXISTS(p,pSingle) &&
231  Fxu_HeapSingleMoveUp( p, pSingle );
232  else if ( FXU_HEAP_SINGLE_CHILD1_EXISTS(p,pSingle) &&
234  Fxu_HeapSingleMoveDn( p, pSingle );
235  else if ( FXU_HEAP_SINGLE_CHILD2_EXISTS(p,pSingle) &&
237  Fxu_HeapSingleMoveDn( p, pSingle );
238 }
static void Fxu_HeapSingleMoveUp(Fxu_HeapSingle *p, Fxu_Single *pSingle)
Definition: fxuHeapS.c:364
#define FXU_HEAP_SINGLE_CHILD2_EXISTS(p, pSingle)
Definition: fxuHeapS.c:32
#define FXU_HEAP_SINGLE_PARENT(p, pSingle)
Definition: fxuHeapS.c:33
#define FXU_HEAP_SINGLE_CHILD1_EXISTS(p, pSingle)
Definition: fxuHeapS.c:31
static void Fxu_HeapSingleMoveDn(Fxu_HeapSingle *p, Fxu_Single *pSingle)
Definition: fxuHeapS.c:392
#define FXU_HEAP_SINGLE_WEIGHT(pSingle)
DECLARATIONS ///.
Definition: fxuHeapS.c:28
#define FXU_HEAP_SINGLE_PARENT_EXISTS(p, pSingle)
Definition: fxuHeapS.c:30
#define FXU_HEAP_SINGLE_CHILD1(p, pSingle)
Definition: fxuHeapS.c:34
#define FXU_HEAP_SINGLE_ASSERT(p, pSingle)
Definition: fxuHeapS.c:36
#define FXU_HEAP_SINGLE_CHILD2(p, pSingle)
Definition: fxuHeapS.c:35