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

Go to the source code of this file.

Functions

static ABC_NAMESPACE_IMPL_START int Ivy_NodeBalance_rec (Ivy_Man_t *pNew, Ivy_Obj_t *pObj, Vec_Vec_t *vStore, int Level, int fUpdateLevel)
 DECLARATIONS ///. More...
 
static Vec_Ptr_tIvy_NodeBalanceCone (Ivy_Obj_t *pObj, Vec_Vec_t *vStore, int Level)
 
static int Ivy_NodeBalanceFindLeft (Vec_Ptr_t *vSuper)
 
static void Ivy_NodeBalancePermute (Ivy_Man_t *p, Vec_Ptr_t *vSuper, int LeftBound, int fExor)
 
static void Ivy_NodeBalancePushUniqueOrderByLevel (Vec_Ptr_t *vStore, Ivy_Obj_t *pObj)
 
Ivy_Man_tIvy_ManBalance (Ivy_Man_t *p, int fUpdateLevel)
 FUNCTION DEFINITIONS ///. More...
 
int Ivy_NodeCompareLevelsDecrease (Ivy_Obj_t **pp1, Ivy_Obj_t **pp2)
 
Ivy_Obj_tIvy_NodeBalanceBuildSuper (Ivy_Man_t *p, Vec_Ptr_t *vSuper, Ivy_Type_t Type, int fUpdateLevel)
 
int Ivy_NodeBalanceCone_rec (Ivy_Obj_t *pRoot, Ivy_Obj_t *pObj, Vec_Ptr_t *vSuper)
 

Function Documentation

Ivy_Man_t* Ivy_ManBalance ( Ivy_Man_t p,
int  fUpdateLevel 
)

FUNCTION DEFINITIONS ///.

FUNCTION DECLARATIONS ///.

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

Synopsis [Performs algebraic balancing of the AIG.]

Description []

SideEffects []

SeeAlso []

Definition at line 51 of file ivyBalance.c.

52 {
53  Ivy_Man_t * pNew;
54  Ivy_Obj_t * pObj, * pDriver;
55  Vec_Vec_t * vStore;
56  int i, NewNodeId;
57  // clean the old manager
59  // create the new manager
60  pNew = Ivy_ManStart();
61  // map the nodes
63  Ivy_ManForEachPi( p, pObj, i )
64  pObj->TravId = Ivy_EdgeFromNode( Ivy_ObjCreatePi(pNew) );
65  // if HAIG is defined, trasfer the pointers to the PIs/latches
66 // if ( p->pHaig )
67 // Ivy_ManHaigTrasfer( p, pNew );
68  // balance the AIG
69  vStore = Vec_VecAlloc( 50 );
70  Ivy_ManForEachPo( p, pObj, i )
71  {
72  pDriver = Ivy_ObjReal( Ivy_ObjChild0(pObj) );
73  NewNodeId = Ivy_NodeBalance_rec( pNew, Ivy_Regular(pDriver), vStore, 0, fUpdateLevel );
74  NewNodeId = Ivy_EdgeNotCond( NewNodeId, Ivy_IsComplement(pDriver) );
75  Ivy_ObjCreatePo( pNew, Ivy_EdgeToNode(pNew, NewNodeId) );
76  }
77  Vec_VecFree( vStore );
78  if ( (i = Ivy_ManCleanup( pNew )) )
79  {
80 // printf( "Cleanup after balancing removed %d dangling nodes.\n", i );
81  }
82  // check the resulting AIG
83  if ( !Ivy_ManCheck(pNew) )
84  printf( "Ivy_ManBalance(): The check has failed.\n" );
85  return pNew;
86 }
int TravId
Definition: ivy.h:76
static int Ivy_IsComplement(Ivy_Obj_t *p)
Definition: ivy.h:196
static Ivy_Obj_t * Ivy_EdgeToNode(Ivy_Man_t *p, Ivy_Edge_t Edge)
Definition: ivy.h:212
static Ivy_Edge_t Ivy_EdgeFromNode(Ivy_Obj_t *pNode)
Definition: ivy.h:211
static Vec_Vec_t * Vec_VecAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecVec.h:145
static Ivy_Obj_t * Ivy_ManConst1(Ivy_Man_t *p)
Definition: ivy.h:199
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static ABC_NAMESPACE_IMPL_START int Ivy_NodeBalance_rec(Ivy_Man_t *pNew, Ivy_Obj_t *pObj, Vec_Vec_t *vStore, int Level, int fUpdateLevel)
DECLARATIONS ///.
Definition: ivyBalance.c:125
#define Ivy_ManForEachPi(p, pObj, i)
ITERATORS ///.
Definition: ivy.h:387
#define Ivy_ManForEachPo(p, pObj, i)
Definition: ivy.h:390
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
Ivy_Man_t * Ivy_ManStart()
DECLARATIONS ///.
Definition: ivyMan.c:45
Ivy_Obj_t * Ivy_ObjReal(Ivy_Obj_t *pObj)
Definition: ivyUtil.c:609
Ivy_Obj_t * Ivy_ObjCreatePo(Ivy_Man_t *p, Ivy_Obj_t *pDriver)
Definition: ivyObj.c:61
static Ivy_Edge_t Ivy_EdgeNotCond(Ivy_Edge_t Edge, int fCond)
Definition: ivy.h:210
Definition: ivy.h:73
static Ivy_Obj_t * Ivy_Regular(Ivy_Obj_t *p)
Definition: ivy.h:193
static Ivy_Obj_t * Ivy_ObjChild0(Ivy_Obj_t *pObj)
Definition: ivy.h:273
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
Definition: ivy.h:46
void Ivy_ManCleanTravId(Ivy_Man_t *p)
Definition: ivyUtil.c:63
Ivy_Obj_t * Ivy_ObjCreatePi(Ivy_Man_t *p)
DECLARATIONS ///.
Definition: ivyObj.c:45
int Ivy_ManCheck(Ivy_Man_t *p)
DECLARATIONS ///.
Definition: ivyCheck.c:45
int Ivy_ManCleanup(Ivy_Man_t *p)
Definition: ivyMan.c:265
int Ivy_NodeBalance_rec ( Ivy_Man_t pNew,
Ivy_Obj_t pObjOld,
Vec_Vec_t vStore,
int  Level,
int  fUpdateLevel 
)
static

DECLARATIONS ///.

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

FileName [ivyBalance.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [And-Inverter Graph package.]

Synopsis [Algebraic AIG balancing.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - May 11, 2006.]

Revision [

Id:
ivyBalance.c,v 1.00 2006/05/11 00:00:00 alanmi Exp

]

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

Synopsis [Returns the ID of new node constructed.]

Description []

SideEffects []

SeeAlso []

Definition at line 125 of file ivyBalance.c.

126 {
127  Ivy_Obj_t * pObjNew;
128  Vec_Ptr_t * vSuper;
129  int i, NewNodeId;
130  assert( !Ivy_IsComplement(pObjOld) );
131  assert( !Ivy_ObjIsBuf(pObjOld) );
132  // return if the result is known
133  if ( Ivy_ObjIsConst1(pObjOld) )
134  return pObjOld->TravId;
135  if ( pObjOld->TravId )
136  return pObjOld->TravId;
137  assert( Ivy_ObjIsNode(pObjOld) );
138  // get the implication supergate
139  vSuper = Ivy_NodeBalanceCone( pObjOld, vStore, Level );
140  if ( vSuper->nSize == 0 )
141  { // it means that the supergate contains two nodes in the opposite polarity
142  pObjOld->TravId = Ivy_EdgeFromNode( Ivy_ManConst0(pNew) );
143  return pObjOld->TravId;
144  }
145  if ( vSuper->nSize < 2 )
146  printf( "BUG!\n" );
147  // for each old node, derive the new well-balanced node
148  for ( i = 0; i < vSuper->nSize; i++ )
149  {
150  NewNodeId = Ivy_NodeBalance_rec( pNew, Ivy_Regular((Ivy_Obj_t *)vSuper->pArray[i]), vStore, Level + 1, fUpdateLevel );
151  NewNodeId = Ivy_EdgeNotCond( NewNodeId, Ivy_IsComplement((Ivy_Obj_t *)vSuper->pArray[i]) );
152  vSuper->pArray[i] = Ivy_EdgeToNode( pNew, NewNodeId );
153  }
154  // build the supergate
155  pObjNew = Ivy_NodeBalanceBuildSuper( pNew, vSuper, Ivy_ObjType(pObjOld), fUpdateLevel );
156  vSuper->nSize = 0;
157  // make sure the balanced node is not assigned
158  assert( pObjOld->TravId == 0 );
159  pObjOld->TravId = Ivy_EdgeFromNode( pObjNew );
160 // assert( pObjOld->Level >= Ivy_Regular(pObjNew)->Level );
161  return pObjOld->TravId;
162 }
int TravId
Definition: ivy.h:76
static int Ivy_IsComplement(Ivy_Obj_t *p)
Definition: ivy.h:196
static Ivy_Obj_t * Ivy_EdgeToNode(Ivy_Man_t *p, Ivy_Edge_t Edge)
Definition: ivy.h:212
static Ivy_Edge_t Ivy_EdgeFromNode(Ivy_Obj_t *pNode)
Definition: ivy.h:211
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static ABC_NAMESPACE_IMPL_START int Ivy_NodeBalance_rec(Ivy_Man_t *pNew, Ivy_Obj_t *pObj, Vec_Vec_t *vStore, int Level, int fUpdateLevel)
DECLARATIONS ///.
Definition: ivyBalance.c:125
static Ivy_Obj_t * Ivy_ManConst0(Ivy_Man_t *p)
Definition: ivy.h:198
Ivy_Obj_t * Ivy_NodeBalanceBuildSuper(Ivy_Man_t *p, Vec_Ptr_t *vSuper, Ivy_Type_t Type, int fUpdateLevel)
Definition: ivyBalance.c:175
static Ivy_Edge_t Ivy_EdgeNotCond(Ivy_Edge_t Edge, int fCond)
Definition: ivy.h:210
Definition: ivy.h:73
static Ivy_Obj_t * Ivy_Regular(Ivy_Obj_t *p)
Definition: ivy.h:193
static Ivy_Type_t Ivy_ObjType(Ivy_Obj_t *pObj)
Definition: ivy.h:231
static int Ivy_ObjIsNode(Ivy_Obj_t *pObj)
Definition: ivy.h:245
static Vec_Ptr_t * Ivy_NodeBalanceCone(Ivy_Obj_t *pObj, Vec_Vec_t *vStore, int Level)
Definition: ivyBalance.c:254
static int Ivy_ObjIsConst1(Ivy_Obj_t *pObj)
Definition: ivy.h:233
static int Ivy_ObjIsBuf(Ivy_Obj_t *pObj)
Definition: ivy.h:244
#define assert(ex)
Definition: util_old.h:213
Ivy_Obj_t* Ivy_NodeBalanceBuildSuper ( Ivy_Man_t p,
Vec_Ptr_t vSuper,
Ivy_Type_t  Type,
int  fUpdateLevel 
)

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

Synopsis [Builds implication supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 175 of file ivyBalance.c.

176 {
177  Ivy_Obj_t * pObj1, * pObj2;
178  int LeftBound;
179  assert( vSuper->nSize > 1 );
180  // sort the new nodes by level in the decreasing order
181  Vec_PtrSort( vSuper, (int (*)(void))Ivy_NodeCompareLevelsDecrease );
182  // balance the nodes
183  while ( vSuper->nSize > 1 )
184  {
185  // find the left bound on the node to be paired
186  LeftBound = (!fUpdateLevel)? 0 : Ivy_NodeBalanceFindLeft( vSuper );
187  // find the node that can be shared (if no such node, randomize choice)
188  Ivy_NodeBalancePermute( p, vSuper, LeftBound, Type == IVY_EXOR );
189  // pull out the last two nodes
190  pObj1 = (Ivy_Obj_t *)Vec_PtrPop(vSuper);
191  pObj2 = (Ivy_Obj_t *)Vec_PtrPop(vSuper);
192  Ivy_NodeBalancePushUniqueOrderByLevel( vSuper, Ivy_Oper(p, pObj1, pObj2, Type) );
193  }
194  return (Ivy_Obj_t *)Vec_PtrEntry(vSuper, 0);
195 }
static int Ivy_NodeBalanceFindLeft(Vec_Ptr_t *vSuper)
Definition: ivyBalance.c:293
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_PtrSort(Vec_Ptr_t *p, int(*Vec_PtrSortCompare)()) ___unused
Definition: vecPtr.h:851
Ivy_Obj_t * Ivy_Oper(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1, Ivy_Type_t Type)
FUNCTION DEFINITIONS ///.
Definition: ivyOper.c:63
int Ivy_NodeCompareLevelsDecrease(Ivy_Obj_t **pp1, Ivy_Obj_t **pp2)
Definition: ivyBalance.c:99
static void * Vec_PtrPop(Vec_Ptr_t *p)
Definition: vecPtr.h:677
Definition: ivy.h:73
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
Definition: ivy.h:59
static void Ivy_NodeBalancePushUniqueOrderByLevel(Vec_Ptr_t *vStore, Ivy_Obj_t *pObj)
Definition: ivyBalance.c:389
#define assert(ex)
Definition: util_old.h:213
static void Ivy_NodeBalancePermute(Ivy_Man_t *p, Vec_Ptr_t *vSuper, int LeftBound, int fExor)
Definition: ivyBalance.c:331
Vec_Ptr_t * Ivy_NodeBalanceCone ( Ivy_Obj_t pObj,
Vec_Vec_t vStore,
int  Level 
)
static

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

Synopsis [Collects the nodes of the supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 254 of file ivyBalance.c.

255 {
256  Vec_Ptr_t * vNodes;
257  int RetValue, i;
258  assert( !Ivy_IsComplement(pObj) );
259  // extend the storage
260  if ( Vec_VecSize( vStore ) <= Level )
261  Vec_VecPush( vStore, Level, 0 );
262  // get the temporary array of nodes
263  vNodes = Vec_VecEntry( vStore, Level );
264  Vec_PtrClear( vNodes );
265  // collect the nodes in the implication supergate
266  RetValue = Ivy_NodeBalanceCone_rec( pObj, pObj, vNodes );
267  assert( vNodes->nSize > 1 );
268  // unmark the visited nodes
269  Vec_PtrForEachEntry( Ivy_Obj_t *, vNodes, pObj, i )
270  Ivy_Regular(pObj)->fMarkB = 0;
271  // if we found the node and its complement in the same implication supergate,
272  // return empty set of nodes (meaning that we should use constant-0 node)
273  if ( RetValue == -1 )
274  vNodes->nSize = 0;
275  return vNodes;
276 }
static int Ivy_IsComplement(Ivy_Obj_t *p)
Definition: ivy.h:196
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static void Vec_VecPush(Vec_Vec_t *p, int Level, void *Entry)
Definition: vecVec.h:456
int Ivy_NodeBalanceCone_rec(Ivy_Obj_t *pRoot, Ivy_Obj_t *pObj, Vec_Ptr_t *vSuper)
Definition: ivyBalance.c:208
if(last==0)
Definition: sparse_int.h:34
Definition: ivy.h:73
static Ivy_Obj_t * Ivy_Regular(Ivy_Obj_t *p)
Definition: ivy.h:193
static int Vec_VecSize(Vec_Vec_t *p)
Definition: vecVec.h:222
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
static Vec_Ptr_t * Vec_VecEntry(Vec_Vec_t *p, int i)
Definition: vecVec.h:271
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
int Ivy_NodeBalanceCone_rec ( Ivy_Obj_t pRoot,
Ivy_Obj_t pObj,
Vec_Ptr_t vSuper 
)

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

Synopsis [Collects the nodes of the supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 208 of file ivyBalance.c.

209 {
210  int RetValue1, RetValue2, i;
211  // check if the node is visited
212  if ( Ivy_Regular(pObj)->fMarkB )
213  {
214  // check if the node occurs in the same polarity
215  for ( i = 0; i < vSuper->nSize; i++ )
216  if ( vSuper->pArray[i] == pObj )
217  return 1;
218  // check if the node is present in the opposite polarity
219  for ( i = 0; i < vSuper->nSize; i++ )
220  if ( vSuper->pArray[i] == Ivy_Not(pObj) )
221  return -1;
222  assert( 0 );
223  return 0;
224  }
225  // if the new node is complemented or a PI, another gate begins
226  if ( pObj != pRoot && (Ivy_IsComplement(pObj) || Ivy_ObjType(pObj) != Ivy_ObjType(pRoot) || Ivy_ObjRefs(pObj) > 1 || Vec_PtrSize(vSuper) > 10000) )
227  {
228  Vec_PtrPush( vSuper, pObj );
229  Ivy_Regular(pObj)->fMarkB = 1;
230  return 0;
231  }
232  assert( !Ivy_IsComplement(pObj) );
233  assert( Ivy_ObjIsNode(pObj) );
234  // go through the branches
235  RetValue1 = Ivy_NodeBalanceCone_rec( pRoot, Ivy_ObjReal( Ivy_ObjChild0(pObj) ), vSuper );
236  RetValue2 = Ivy_NodeBalanceCone_rec( pRoot, Ivy_ObjReal( Ivy_ObjChild1(pObj) ), vSuper );
237  if ( RetValue1 == -1 || RetValue2 == -1 )
238  return -1;
239  // return 1 if at least one branch has a duplicate
240  return RetValue1 || RetValue2;
241 }
static int Ivy_IsComplement(Ivy_Obj_t *p)
Definition: ivy.h:196
int Ivy_NodeBalanceCone_rec(Ivy_Obj_t *pRoot, Ivy_Obj_t *pObj, Vec_Ptr_t *vSuper)
Definition: ivyBalance.c:208
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Ivy_Obj_t * Ivy_ObjReal(Ivy_Obj_t *pObj)
Definition: ivyUtil.c:609
static int Ivy_ObjRefs(Ivy_Obj_t *pObj)
Definition: ivy.h:264
static Ivy_Obj_t * Ivy_Regular(Ivy_Obj_t *p)
Definition: ivy.h:193
static Ivy_Type_t Ivy_ObjType(Ivy_Obj_t *pObj)
Definition: ivy.h:231
static int Ivy_ObjIsNode(Ivy_Obj_t *pObj)
Definition: ivy.h:245
static Ivy_Obj_t * Ivy_ObjChild0(Ivy_Obj_t *pObj)
Definition: ivy.h:273
unsigned fMarkB
Definition: ivy.h:79
static Ivy_Obj_t * Ivy_Not(Ivy_Obj_t *p)
Definition: ivy.h:194
static Ivy_Obj_t * Ivy_ObjChild1(Ivy_Obj_t *pObj)
Definition: ivy.h:274
#define assert(ex)
Definition: util_old.h:213
int Ivy_NodeBalanceFindLeft ( Vec_Ptr_t vSuper)
static

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

Synopsis [Finds the left bound on the next candidate to be paired.]

Description [The nodes in the array are in the decreasing order of levels. The last node in the array has the smallest level. By default it would be paired with the next node on the left. However, it may be possible to pair it with some other node on the left, in such a way that the new node is shared. This procedure finds the index of the left-most node, which can be paired with the last node.]

SideEffects []

SeeAlso []

Definition at line 293 of file ivyBalance.c.

294 {
295  Ivy_Obj_t * pObjRight, * pObjLeft;
296  int Current;
297  // if two or less nodes, pair with the first
298  if ( Vec_PtrSize(vSuper) < 3 )
299  return 0;
300  // set the pointer to the one before the last
301  Current = Vec_PtrSize(vSuper) - 2;
302  pObjRight = (Ivy_Obj_t *)Vec_PtrEntry( vSuper, Current );
303  // go through the nodes to the left of this one
304  for ( Current--; Current >= 0; Current-- )
305  {
306  // get the next node on the left
307  pObjLeft = (Ivy_Obj_t *)Vec_PtrEntry( vSuper, Current );
308  // if the level of this node is different, quit the loop
309  if ( Ivy_Regular(pObjLeft)->Level != Ivy_Regular(pObjRight)->Level )
310  break;
311  }
312  Current++;
313  // get the node, for which the equality holds
314  pObjLeft = (Ivy_Obj_t *)Vec_PtrEntry( vSuper, Current );
315  assert( Ivy_Regular(pObjLeft)->Level == Ivy_Regular(pObjRight)->Level );
316  return Current;
317 }
unsigned Level
Definition: ivy.h:84
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Definition: ivy.h:73
static Ivy_Obj_t * Ivy_Regular(Ivy_Obj_t *p)
Definition: ivy.h:193
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
#define assert(ex)
Definition: util_old.h:213
void Ivy_NodeBalancePermute ( Ivy_Man_t p,
Vec_Ptr_t vSuper,
int  LeftBound,
int  fExor 
)
static

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

Synopsis [Moves closer to the end the node that is best for sharing.]

Description [If there is no node with sharing, randomly chooses one of the legal nodes.]

SideEffects []

SeeAlso []

Definition at line 331 of file ivyBalance.c.

332 {
333  Ivy_Obj_t * pObj1, * pObj2, * pObj3, * pGhost;
334  int RightBound, i;
335  // get the right bound
336  RightBound = Vec_PtrSize(vSuper) - 2;
337  assert( LeftBound <= RightBound );
338  if ( LeftBound == RightBound )
339  return;
340  // get the two last nodes
341  pObj1 = (Ivy_Obj_t *)Vec_PtrEntry( vSuper, RightBound + 1 );
342  pObj2 = (Ivy_Obj_t *)Vec_PtrEntry( vSuper, RightBound );
343  if ( Ivy_Regular(pObj1) == p->pConst1 || Ivy_Regular(pObj2) == p->pConst1 )
344  return;
345  // find the first node that can be shared
346  for ( i = RightBound; i >= LeftBound; i-- )
347  {
348  pObj3 = (Ivy_Obj_t *)Vec_PtrEntry( vSuper, i );
349  if ( Ivy_Regular(pObj3) == p->pConst1 )
350  {
351  Vec_PtrWriteEntry( vSuper, i, pObj2 );
352  Vec_PtrWriteEntry( vSuper, RightBound, pObj3 );
353  return;
354  }
355  pGhost = Ivy_ObjCreateGhost( p, pObj1, pObj3, fExor? IVY_EXOR : IVY_AND, IVY_INIT_NONE );
356  if ( Ivy_TableLookup( p, pGhost ) )
357  {
358  if ( pObj3 == pObj2 )
359  return;
360  Vec_PtrWriteEntry( vSuper, i, pObj2 );
361  Vec_PtrWriteEntry( vSuper, RightBound, pObj3 );
362  return;
363  }
364  }
365 /*
366  // we did not find the node to share, randomize choice
367  {
368  int Choice = rand() % (RightBound - LeftBound + 1);
369  pObj3 = Vec_PtrEntry( vSuper, LeftBound + Choice );
370  if ( pObj3 == pObj2 )
371  return;
372  Vec_PtrWriteEntry( vSuper, LeftBound + Choice, pObj2 );
373  Vec_PtrWriteEntry( vSuper, RightBound, pObj3 );
374  }
375 */
376 }
Definition: ivy.h:58
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Ivy_Obj_t * Ivy_TableLookup(Ivy_Man_t *p, Ivy_Obj_t *pObj)
FUNCTION DEFINITIONS ///.
Definition: ivyTable.c:71
Definition: ivy.h:73
static Ivy_Obj_t * Ivy_Regular(Ivy_Obj_t *p)
Definition: ivy.h:193
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static Ivy_Obj_t * Ivy_ObjCreateGhost(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1, Ivy_Type_t Type, Ivy_Init_t Init)
Definition: ivy.h:308
Definition: ivy.h:59
#define assert(ex)
Definition: util_old.h:213
void Ivy_NodeBalancePushUniqueOrderByLevel ( Vec_Ptr_t vStore,
Ivy_Obj_t pObj 
)
static

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

Synopsis [Inserts a new node in the order by levels.]

Description []

SideEffects []

SeeAlso []

Definition at line 389 of file ivyBalance.c.

390 {
391  Ivy_Obj_t * pObj1, * pObj2;
392  int i;
393  if ( Vec_PtrPushUnique(vStore, pObj) )
394  return;
395  // find the p of the node
396  for ( i = vStore->nSize-1; i > 0; i-- )
397  {
398  pObj1 = (Ivy_Obj_t *)vStore->pArray[i ];
399  pObj2 = (Ivy_Obj_t *)vStore->pArray[i-1];
400  if ( Ivy_Regular(pObj1)->Level <= Ivy_Regular(pObj2)->Level )
401  break;
402  vStore->pArray[i ] = pObj2;
403  vStore->pArray[i-1] = pObj1;
404  }
405 }
unsigned Level
Definition: ivy.h:84
static int Vec_PtrPushUnique(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:656
Definition: ivy.h:73
static Ivy_Obj_t * Ivy_Regular(Ivy_Obj_t *p)
Definition: ivy.h:193
int Ivy_NodeCompareLevelsDecrease ( Ivy_Obj_t **  pp1,
Ivy_Obj_t **  pp2 
)

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

Synopsis [Procedure used for sorting the nodes in decreasing order of levels.]

Description []

SideEffects []

SeeAlso []

Definition at line 99 of file ivyBalance.c.

100 {
101  int Diff = Ivy_Regular(*pp1)->Level - Ivy_Regular(*pp2)->Level;
102  if ( Diff > 0 )
103  return -1;
104  if ( Diff < 0 )
105  return 1;
106  Diff = Ivy_Regular(*pp1)->Id - Ivy_Regular(*pp2)->Id;
107  if ( Diff > 0 )
108  return -1;
109  if ( Diff < 0 )
110  return 1;
111  return 0;
112 }
unsigned Level
Definition: ivy.h:84
int Id
Definition: ivy.h:75
if(last==0)
Definition: sparse_int.h:34
static Ivy_Obj_t * Ivy_Regular(Ivy_Obj_t *p)
Definition: ivy.h:193