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

Go to the source code of this file.

Macros

#define FXU_HEAP_DOUBLE_WEIGHT(pDiv)   ((pDiv)->Weight)
 DECLARATIONS ///. More...
 
#define FXU_HEAP_DOUBLE_CURRENT(p, pDiv)   ((p)->pTree[(pDiv)->HNum])
 
#define FXU_HEAP_DOUBLE_PARENT_EXISTS(p, pDiv)   ((pDiv)->HNum > 1)
 
#define FXU_HEAP_DOUBLE_CHILD1_EXISTS(p, pDiv)   (((pDiv)->HNum << 1) <= p->nItems)
 
#define FXU_HEAP_DOUBLE_CHILD2_EXISTS(p, pDiv)   ((((pDiv)->HNum << 1)+1) <= p->nItems)
 
#define FXU_HEAP_DOUBLE_PARENT(p, pDiv)   ((p)->pTree[(pDiv)->HNum >> 1])
 
#define FXU_HEAP_DOUBLE_CHILD1(p, pDiv)   ((p)->pTree[(pDiv)->HNum << 1])
 
#define FXU_HEAP_DOUBLE_CHILD2(p, pDiv)   ((p)->pTree[((pDiv)->HNum << 1)+1])
 
#define FXU_HEAP_DOUBLE_ASSERT(p, pDiv)   assert( (pDiv)->HNum >= 1 && (pDiv)->HNum <= p->nItemsAlloc )
 

Functions

static void Fxu_HeapDoubleResize (Fxu_HeapDouble *p)
 
static void Fxu_HeapDoubleSwap (Fxu_Double **pDiv1, Fxu_Double **pDiv2)
 
static void Fxu_HeapDoubleMoveUp (Fxu_HeapDouble *p, Fxu_Double *pDiv)
 
static void Fxu_HeapDoubleMoveDn (Fxu_HeapDouble *p, Fxu_Double *pDiv)
 
Fxu_HeapDoubleFxu_HeapDoubleStart ()
 FUNCTION DEFINITIONS ///. More...
 
void Fxu_HeapDoubleStop (Fxu_HeapDouble *p)
 
void Fxu_HeapDoublePrint (FILE *pFile, Fxu_HeapDouble *p)
 
void Fxu_HeapDoubleCheck (Fxu_HeapDouble *p)
 
void Fxu_HeapDoubleCheckOne (Fxu_HeapDouble *p, Fxu_Double *pDiv)
 
void Fxu_HeapDoubleInsert (Fxu_HeapDouble *p, Fxu_Double *pDiv)
 
void Fxu_HeapDoubleUpdate (Fxu_HeapDouble *p, Fxu_Double *pDiv)
 
void Fxu_HeapDoubleDelete (Fxu_HeapDouble *p, Fxu_Double *pDiv)
 
Fxu_DoubleFxu_HeapDoubleReadMax (Fxu_HeapDouble *p)
 
Fxu_DoubleFxu_HeapDoubleGetMax (Fxu_HeapDouble *p)
 
int Fxu_HeapDoubleReadMaxWeight (Fxu_HeapDouble *p)
 

Macro Definition Documentation

#define FXU_HEAP_DOUBLE_ASSERT (   p,
  pDiv 
)    assert( (pDiv)->HNum >= 1 && (pDiv)->HNum <= p->nItemsAlloc )

Definition at line 36 of file fxuHeapD.c.

#define FXU_HEAP_DOUBLE_CHILD1 (   p,
  pDiv 
)    ((p)->pTree[(pDiv)->HNum << 1])

Definition at line 34 of file fxuHeapD.c.

#define FXU_HEAP_DOUBLE_CHILD1_EXISTS (   p,
  pDiv 
)    (((pDiv)->HNum << 1) <= p->nItems)

Definition at line 31 of file fxuHeapD.c.

#define FXU_HEAP_DOUBLE_CHILD2 (   p,
  pDiv 
)    ((p)->pTree[((pDiv)->HNum << 1)+1])

Definition at line 35 of file fxuHeapD.c.

#define FXU_HEAP_DOUBLE_CHILD2_EXISTS (   p,
  pDiv 
)    ((((pDiv)->HNum << 1)+1) <= p->nItems)

Definition at line 32 of file fxuHeapD.c.

#define FXU_HEAP_DOUBLE_CURRENT (   p,
  pDiv 
)    ((p)->pTree[(pDiv)->HNum])

Definition at line 29 of file fxuHeapD.c.

#define FXU_HEAP_DOUBLE_PARENT (   p,
  pDiv 
)    ((p)->pTree[(pDiv)->HNum >> 1])

Definition at line 33 of file fxuHeapD.c.

#define FXU_HEAP_DOUBLE_PARENT_EXISTS (   p,
  pDiv 
)    ((pDiv)->HNum > 1)

Definition at line 30 of file fxuHeapD.c.

#define FXU_HEAP_DOUBLE_WEIGHT (   pDiv)    ((pDiv)->Weight)

DECLARATIONS ///.

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

FileName [fxuHeapD.c]

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

Synopsis [The priority queue for double cube divisors.]

Author [MVSIS Group]

Affiliation [UC Berkeley]

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

Revision [

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

]

Definition at line 28 of file fxuHeapD.c.

Function Documentation

void Fxu_HeapDoubleCheck ( Fxu_HeapDouble p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 152 of file fxuHeapD.c.

153 {
154  Fxu_Double * pDiv;
155  Fxu_HeapDoubleForEachItem( p, pDiv )
156  {
157  assert( pDiv->HNum == p->i );
158  Fxu_HeapDoubleCheckOne( p, pDiv );
159  }
160 }
#define Fxu_HeapDoubleForEachItem(Heap, Div)
Definition: fxuInt.h:375
int HNum
Definition: fxuInt.h:257
void Fxu_HeapDoubleCheckOne(Fxu_HeapDouble *p, Fxu_Double *pDiv)
Definition: fxuHeapD.c:173
#define assert(ex)
Definition: util_old.h:213
void Fxu_HeapDoubleCheckOne ( Fxu_HeapDouble p,
Fxu_Double pDiv 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 173 of file fxuHeapD.c.

174 {
175  int Weight1, Weight2;
176  if ( FXU_HEAP_DOUBLE_CHILD1_EXISTS(p,pDiv) )
177  {
178  Weight1 = FXU_HEAP_DOUBLE_WEIGHT(pDiv);
179  Weight2 = FXU_HEAP_DOUBLE_WEIGHT( FXU_HEAP_DOUBLE_CHILD1(p,pDiv) );
180  assert( Weight1 >= Weight2 );
181  }
182  if ( FXU_HEAP_DOUBLE_CHILD2_EXISTS(p,pDiv) )
183  {
184  Weight1 = FXU_HEAP_DOUBLE_WEIGHT(pDiv);
185  Weight2 = FXU_HEAP_DOUBLE_WEIGHT( FXU_HEAP_DOUBLE_CHILD2(p,pDiv) );
186  assert( Weight1 >= Weight2 );
187  }
188 }
#define FXU_HEAP_DOUBLE_CHILD2(p, pDiv)
Definition: fxuHeapD.c:35
#define FXU_HEAP_DOUBLE_WEIGHT(pDiv)
DECLARATIONS ///.
Definition: fxuHeapD.c:28
#define FXU_HEAP_DOUBLE_CHILD2_EXISTS(p, pDiv)
Definition: fxuHeapD.c:32
#define FXU_HEAP_DOUBLE_CHILD1(p, pDiv)
Definition: fxuHeapD.c:34
#define FXU_HEAP_DOUBLE_CHILD1_EXISTS(p, pDiv)
Definition: fxuHeapD.c:31
#define assert(ex)
Definition: util_old.h:213
void Fxu_HeapDoubleDelete ( Fxu_HeapDouble p,
Fxu_Double pDiv 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 250 of file fxuHeapD.c.

251 {
252  FXU_HEAP_DOUBLE_ASSERT(p,pDiv);
253  // put the last entry to the deleted place
254  // decrement the number of entries
255  p->pTree[pDiv->HNum] = p->pTree[p->nItems--];
256  p->pTree[pDiv->HNum]->HNum = pDiv->HNum;
257  // move the top entry down if necessary
258  Fxu_HeapDoubleUpdate( p, p->pTree[pDiv->HNum] );
259  pDiv->HNum = 0;
260 }
void Fxu_HeapDoubleUpdate(Fxu_HeapDouble *p, Fxu_Double *pDiv)
Definition: fxuHeapD.c:223
int nItems
Definition: fxuInt.h:145
int HNum
Definition: fxuInt.h:257
Fxu_Double ** pTree
Definition: fxuInt.h:144
#define FXU_HEAP_DOUBLE_ASSERT(p, pDiv)
Definition: fxuHeapD.c:36
Fxu_Double* Fxu_HeapDoubleGetMax ( Fxu_HeapDouble p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 291 of file fxuHeapD.c.

292 {
293  Fxu_Double * pDiv;
294  if ( p->nItems == 0 )
295  return NULL;
296  // prepare the return value
297  pDiv = p->pTree[1];
298  pDiv->HNum = 0;
299  // put the last entry on top
300  // decrement the number of entries
301  p->pTree[1] = p->pTree[p->nItems--];
302  p->pTree[1]->HNum = 1;
303  // move the top entry down if necessary
304  Fxu_HeapDoubleMoveDn( p, p->pTree[1] );
305  return pDiv;
306 }
int nItems
Definition: fxuInt.h:145
static void Fxu_HeapDoubleMoveDn(Fxu_HeapDouble *p, Fxu_Double *pDiv)
Definition: fxuHeapD.c:391
int HNum
Definition: fxuInt.h:257
Fxu_Double ** pTree
Definition: fxuInt.h:144
void Fxu_HeapDoubleInsert ( Fxu_HeapDouble p,
Fxu_Double pDiv 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 201 of file fxuHeapD.c.

202 {
203  if ( p->nItems == p->nItemsAlloc )
205  // put the last entry to the last place and move up
206  p->pTree[++p->nItems] = pDiv;
207  pDiv->HNum = p->nItems;
208  // move the last entry up if necessary
209  Fxu_HeapDoubleMoveUp( p, pDiv );
210 }
static void Fxu_HeapDoubleMoveUp(Fxu_HeapDouble *p, Fxu_Double *pDiv)
Definition: fxuHeapD.c:363
int nItems
Definition: fxuInt.h:145
int HNum
Definition: fxuInt.h:257
int nItemsAlloc
Definition: fxuInt.h:146
static void Fxu_HeapDoubleResize(Fxu_HeapDouble *p)
Definition: fxuHeapD.c:82
Fxu_Double ** pTree
Definition: fxuInt.h:144
void Fxu_HeapDoubleMoveDn ( Fxu_HeapDouble p,
Fxu_Double pDiv 
)
static

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 391 of file fxuHeapD.c.

392 {
393  Fxu_Double ** ppChild1, ** ppChild2, ** ppDiv;
394  ppDiv = &FXU_HEAP_DOUBLE_CURRENT(p, pDiv);
395  while ( FXU_HEAP_DOUBLE_CHILD1_EXISTS(p,*ppDiv) )
396  { // if Child1 does not exist, Child2 also does not exists
397 
398  // get the children
399  ppChild1 = &FXU_HEAP_DOUBLE_CHILD1(p,*ppDiv);
400  if ( FXU_HEAP_DOUBLE_CHILD2_EXISTS(p,*ppDiv) )
401  {
402  ppChild2 = &FXU_HEAP_DOUBLE_CHILD2(p,*ppDiv);
403 
404  // consider two cases
405  if ( FXU_HEAP_DOUBLE_WEIGHT(*ppDiv) >= FXU_HEAP_DOUBLE_WEIGHT(*ppChild1) &&
406  FXU_HEAP_DOUBLE_WEIGHT(*ppDiv) >= FXU_HEAP_DOUBLE_WEIGHT(*ppChild2) )
407  { // Div is larger than both, skip
408  break;
409  }
410  else
411  { // Div is smaller than one of them, then swap it with larger
412  if ( FXU_HEAP_DOUBLE_WEIGHT(*ppChild1) >= FXU_HEAP_DOUBLE_WEIGHT(*ppChild2) )
413  {
414  Fxu_HeapDoubleSwap( ppDiv, ppChild1 );
415  // update the pointer
416  ppDiv = ppChild1;
417  }
418  else
419  {
420  Fxu_HeapDoubleSwap( ppDiv, ppChild2 );
421  // update the pointer
422  ppDiv = ppChild2;
423  }
424  }
425  }
426  else // Child2 does not exist
427  {
428  // consider two cases
429  if ( FXU_HEAP_DOUBLE_WEIGHT(*ppDiv) >= FXU_HEAP_DOUBLE_WEIGHT(*ppChild1) )
430  { // Div is larger than Child1, skip
431  break;
432  }
433  else
434  { // Div is smaller than Child1, then swap them
435  Fxu_HeapDoubleSwap( ppDiv, ppChild1 );
436  // update the pointer
437  ppDiv = ppChild1;
438  }
439  }
440  }
441 }
#define FXU_HEAP_DOUBLE_CHILD2(p, pDiv)
Definition: fxuHeapD.c:35
#define FXU_HEAP_DOUBLE_WEIGHT(pDiv)
DECLARATIONS ///.
Definition: fxuHeapD.c:28
#define FXU_HEAP_DOUBLE_CHILD2_EXISTS(p, pDiv)
Definition: fxuHeapD.c:32
#define FXU_HEAP_DOUBLE_CURRENT(p, pDiv)
Definition: fxuHeapD.c:29
#define FXU_HEAP_DOUBLE_CHILD1(p, pDiv)
Definition: fxuHeapD.c:34
#define FXU_HEAP_DOUBLE_CHILD1_EXISTS(p, pDiv)
Definition: fxuHeapD.c:31
static void Fxu_HeapDoubleSwap(Fxu_Double **pDiv1, Fxu_Double **pDiv2)
Definition: fxuHeapD.c:340
void Fxu_HeapDoubleMoveUp ( Fxu_HeapDouble p,
Fxu_Double pDiv 
)
static

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 363 of file fxuHeapD.c.

364 {
365  Fxu_Double ** ppDiv, ** ppPar;
366  ppDiv = &FXU_HEAP_DOUBLE_CURRENT(p, pDiv);
367  while ( FXU_HEAP_DOUBLE_PARENT_EXISTS(p,*ppDiv) )
368  {
369  ppPar = &FXU_HEAP_DOUBLE_PARENT(p,*ppDiv);
370  if ( FXU_HEAP_DOUBLE_WEIGHT(*ppDiv) > FXU_HEAP_DOUBLE_WEIGHT(*ppPar) )
371  {
372  Fxu_HeapDoubleSwap( ppDiv, ppPar );
373  ppDiv = ppPar;
374  }
375  else
376  break;
377  }
378 }
#define FXU_HEAP_DOUBLE_WEIGHT(pDiv)
DECLARATIONS ///.
Definition: fxuHeapD.c:28
#define FXU_HEAP_DOUBLE_CURRENT(p, pDiv)
Definition: fxuHeapD.c:29
#define FXU_HEAP_DOUBLE_PARENT(p, pDiv)
Definition: fxuHeapD.c:33
#define FXU_HEAP_DOUBLE_PARENT_EXISTS(p, pDiv)
Definition: fxuHeapD.c:30
static void Fxu_HeapDoubleSwap(Fxu_Double **pDiv1, Fxu_Double **pDiv2)
Definition: fxuHeapD.c:340
void Fxu_HeapDoublePrint ( FILE *  pFile,
Fxu_HeapDouble p 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 117 of file fxuHeapD.c.

118 {
119  Fxu_Double * pDiv;
120  int Counter = 1;
121  int Degree = 1;
122 
123  Fxu_HeapDoubleCheck( p );
124  fprintf( pFile, "The contents of the heap:\n" );
125  fprintf( pFile, "Level %d: ", Degree );
126  Fxu_HeapDoubleForEachItem( p, pDiv )
127  {
128  assert( Counter == p->pTree[Counter]->HNum );
129  fprintf( pFile, "%2d=%3d ", Counter, FXU_HEAP_DOUBLE_WEIGHT(p->pTree[Counter]) );
130  if ( ++Counter == (1 << Degree) )
131  {
132  fprintf( pFile, "\n" );
133  Degree++;
134  fprintf( pFile, "Level %d: ", Degree );
135  }
136  }
137  fprintf( pFile, "\n" );
138  fprintf( pFile, "End of the heap printout.\n" );
139 }
#define FXU_HEAP_DOUBLE_WEIGHT(pDiv)
DECLARATIONS ///.
Definition: fxuHeapD.c:28
void Fxu_HeapDoubleCheck(Fxu_HeapDouble *p)
Definition: fxuHeapD.c:152
#define Fxu_HeapDoubleForEachItem(Heap, Div)
Definition: fxuInt.h:375
static int Counter
int HNum
Definition: fxuInt.h:257
Fxu_Double ** pTree
Definition: fxuInt.h:144
#define assert(ex)
Definition: util_old.h:213
Fxu_Double* Fxu_HeapDoubleReadMax ( Fxu_HeapDouble p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 273 of file fxuHeapD.c.

274 {
275  if ( p->nItems == 0 )
276  return NULL;
277  return p->pTree[1];
278 }
int nItems
Definition: fxuInt.h:145
Fxu_Double ** pTree
Definition: fxuInt.h:144
int Fxu_HeapDoubleReadMaxWeight ( Fxu_HeapDouble p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 319 of file fxuHeapD.c.

320 {
321  if ( p->nItems == 0 )
322  return -1;
323  else
324  return FXU_HEAP_DOUBLE_WEIGHT(p->pTree[1]);
325 }
#define FXU_HEAP_DOUBLE_WEIGHT(pDiv)
DECLARATIONS ///.
Definition: fxuHeapD.c:28
int nItems
Definition: fxuInt.h:145
Fxu_Double ** pTree
Definition: fxuInt.h:144
void Fxu_HeapDoubleResize ( Fxu_HeapDouble p)
static

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 82 of file fxuHeapD.c.

83 {
84  p->nItemsAlloc *= 2;
85  p->pTree = ABC_REALLOC( Fxu_Double *, p->pTree, p->nItemsAlloc + 1 );
86 }
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
int nItemsAlloc
Definition: fxuInt.h:146
Fxu_Double ** pTree
Definition: fxuInt.h:144
Fxu_HeapDouble* Fxu_HeapDoubleStart ( )

FUNCTION DEFINITIONS ///.

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 58 of file fxuHeapD.c.

59 {
60  Fxu_HeapDouble * p;
61  p = ABC_ALLOC( Fxu_HeapDouble, 1 );
62  memset( p, 0, sizeof(Fxu_HeapDouble) );
63  p->nItems = 0;
64  p->nItemsAlloc = 10000;
65  p->pTree = ABC_ALLOC( Fxu_Double *, p->nItemsAlloc + 1 );
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
int nItems
Definition: fxuInt.h:145
int nItemsAlloc
Definition: fxuInt.h:146
Fxu_Double ** pTree
Definition: fxuInt.h:144
void Fxu_HeapDoubleStop ( Fxu_HeapDouble p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 99 of file fxuHeapD.c.

100 {
101  ABC_FREE( p->pTree );
102  ABC_FREE( p );
103 }
#define ABC_FREE(obj)
Definition: abc_global.h:232
Fxu_Double ** pTree
Definition: fxuInt.h:144
void Fxu_HeapDoubleSwap ( Fxu_Double **  pDiv1,
Fxu_Double **  pDiv2 
)
static

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 340 of file fxuHeapD.c.

341 {
342  Fxu_Double * pDiv;
343  int Temp;
344  pDiv = *pDiv1;
345  *pDiv1 = *pDiv2;
346  *pDiv2 = pDiv;
347  Temp = (*pDiv1)->HNum;
348  (*pDiv1)->HNum = (*pDiv2)->HNum;
349  (*pDiv2)->HNum = Temp;
350 }
int HNum
Definition: fxuInt.h:257
void Fxu_HeapDoubleUpdate ( Fxu_HeapDouble p,
Fxu_Double pDiv 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 223 of file fxuHeapD.c.

224 {
225 //printf( "Updating divisor %d.\n", pDiv->Num );
226 
227  FXU_HEAP_DOUBLE_ASSERT(p,pDiv);
228  if ( FXU_HEAP_DOUBLE_PARENT_EXISTS(p,pDiv) &&
230  Fxu_HeapDoubleMoveUp( p, pDiv );
231  else if ( FXU_HEAP_DOUBLE_CHILD1_EXISTS(p,pDiv) &&
233  Fxu_HeapDoubleMoveDn( p, pDiv );
234  else if ( FXU_HEAP_DOUBLE_CHILD2_EXISTS(p,pDiv) &&
236  Fxu_HeapDoubleMoveDn( p, pDiv );
237 }
#define FXU_HEAP_DOUBLE_CHILD2(p, pDiv)
Definition: fxuHeapD.c:35
#define FXU_HEAP_DOUBLE_WEIGHT(pDiv)
DECLARATIONS ///.
Definition: fxuHeapD.c:28
static void Fxu_HeapDoubleMoveUp(Fxu_HeapDouble *p, Fxu_Double *pDiv)
Definition: fxuHeapD.c:363
#define FXU_HEAP_DOUBLE_CHILD2_EXISTS(p, pDiv)
Definition: fxuHeapD.c:32
#define FXU_HEAP_DOUBLE_CHILD1(p, pDiv)
Definition: fxuHeapD.c:34
#define FXU_HEAP_DOUBLE_PARENT(p, pDiv)
Definition: fxuHeapD.c:33
static void Fxu_HeapDoubleMoveDn(Fxu_HeapDouble *p, Fxu_Double *pDiv)
Definition: fxuHeapD.c:391
#define FXU_HEAP_DOUBLE_PARENT_EXISTS(p, pDiv)
Definition: fxuHeapD.c:30
#define FXU_HEAP_DOUBLE_CHILD1_EXISTS(p, pDiv)
Definition: fxuHeapD.c:31
#define FXU_HEAP_DOUBLE_ASSERT(p, pDiv)
Definition: fxuHeapD.c:36