abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
aigOrder.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [aigOrder.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [AIG package.]
8 
9  Synopsis [Dynamically updated topological order.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: aigOrder.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "aig.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Initializes the order datastructure.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
46 {
47  Aig_Obj_t * pObj;
48  int i;
49  assert( Aig_ManBufNum(p) == 0 );
50  // allocate order datastructure
51  assert( p->pOrderData == NULL );
52  p->nOrderAlloc = 2 * Aig_ManObjNumMax(p);
53  if ( p->nOrderAlloc < (1<<12) )
54  p->nOrderAlloc = (1<<12);
55  p->pOrderData = ABC_ALLOC( unsigned, 2 * p->nOrderAlloc );
56  memset( p->pOrderData, 0xFF, sizeof(unsigned) * 2 * p->nOrderAlloc );
57  // add the constant node
58  p->pOrderData[0] = p->pOrderData[1] = 0;
59  p->iPrev = p->iNext = 0;
60  // add the internal nodes
61  Aig_ManForEachNode( p, pObj, i )
62  Aig_ObjOrderInsert( p, pObj->Id );
63 }
64 
65 /**Function*************************************************************
66 
67  Synopsis [Deletes the order datastructure.]
68 
69  Description []
70 
71  SideEffects []
72 
73  SeeAlso []
74 
75 ***********************************************************************/
77 {
78  assert( p->pOrderData );
79  ABC_FREE( p->pOrderData );
80  p->nOrderAlloc = 0;
81  p->iPrev = p->iNext = 0;
82 }
83 
84 /**Function*************************************************************
85 
86  Synopsis [Inserts an entry before iNext.]
87 
88  Description []
89 
90  SideEffects []
91 
92  SeeAlso []
93 
94 ***********************************************************************/
95 void Aig_ObjOrderInsert( Aig_Man_t * p, int ObjId )
96 {
97  int iPrev;
98  assert( ObjId != 0 );
99  assert( Aig_ObjIsNode( Aig_ManObj(p, ObjId) ) );
100  if ( ObjId >= p->nOrderAlloc )
101  {
102  int nOrderAlloc = 2 * ObjId;
103  p->pOrderData = ABC_REALLOC( unsigned, p->pOrderData, 2 * nOrderAlloc );
104  memset( p->pOrderData + 2 * p->nOrderAlloc, 0xFF, sizeof(unsigned) * 2 * (nOrderAlloc - p->nOrderAlloc) );
105  p->nOrderAlloc = nOrderAlloc;
106  }
107  assert( p->pOrderData[2*ObjId] == 0xFFFFFFFF ); // prev
108  assert( p->pOrderData[2*ObjId+1] == 0xFFFFFFFF ); // next
109  iPrev = p->pOrderData[2*p->iNext];
110  assert( p->pOrderData[2*iPrev+1] == (unsigned)p->iNext );
111  p->pOrderData[2*ObjId] = iPrev;
112  p->pOrderData[2*iPrev+1] = ObjId;
113  p->pOrderData[2*p->iNext] = ObjId;
114  p->pOrderData[2*ObjId+1] = p->iNext;
115  p->nAndTotal++;
116 }
117 
118 /**Function*************************************************************
119 
120  Synopsis [Removes the entry.]
121 
122  Description [If iPrev is removed, it slides backward.
123  If iNext is removed, it slides forward.]
124 
125  SideEffects []
126 
127  SeeAlso []
128 
129 ***********************************************************************/
130 void Aig_ObjOrderRemove( Aig_Man_t * p, int ObjId )
131 {
132  int iPrev, iNext;
133  assert( ObjId != 0 );
134  assert( Aig_ObjIsNode( Aig_ManObj(p, ObjId) ) );
135  iPrev = p->pOrderData[2*ObjId];
136  iNext = p->pOrderData[2*ObjId+1];
137  p->pOrderData[2*ObjId] = 0xFFFFFFFF;
138  p->pOrderData[2*ObjId+1] = 0xFFFFFFFF;
139  p->pOrderData[2*iNext] = iPrev;
140  p->pOrderData[2*iPrev+1] = iNext;
141  if ( p->iPrev == ObjId )
142  {
143  p->nAndPrev--;
144  p->iPrev = iPrev;
145  }
146  if ( p->iNext == ObjId )
147  p->iNext = iNext;
148  p->nAndTotal--;
149 }
150 
151 /**Function*************************************************************
152 
153  Synopsis [Advances the order forward.]
154 
155  Description []
156 
157  SideEffects []
158 
159  SeeAlso []
160 
161 ***********************************************************************/
163 {
164  assert( p->pOrderData );
165  assert( p->pOrderData[2*p->iPrev+1] == (unsigned)p->iNext );
166  p->iPrev = p->iNext;
167  p->nAndPrev++;
168 }
169 
170 ////////////////////////////////////////////////////////////////////////
171 /// END OF FILE ///
172 ////////////////////////////////////////////////////////////////////////
173 
174 
176 
char * memset()
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_REALLOC(type, obj, num)
Definition: abc_global.h:233
void Aig_ObjOrderRemove(Aig_Man_t *p, int ObjId)
Definition: aigOrder.c:130
void Aig_ManOrderStop(Aig_Man_t *p)
Definition: aigOrder.c:76
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static Aig_Obj_t * Aig_ManObj(Aig_Man_t *p, int i)
Definition: aig.h:270
static int Aig_ManBufNum(Aig_Man_t *p)
Definition: aig.h:253
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Definition: aig.h:69
ABC_NAMESPACE_IMPL_START void Aig_ManOrderStart(Aig_Man_t *p)
DECLARATIONS ///.
Definition: aigOrder.c:45
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define assert(ex)
Definition: util_old.h:213
void Aig_ObjOrderInsert(Aig_Man_t *p, int ObjId)
Definition: aigOrder.c:95
void Aig_ObjOrderAdvance(Aig_Man_t *p)
Definition: aigOrder.c:162
int Id
Definition: aig.h:85