abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mvcList.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [mvcList.c]
4 
5  PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]
6 
7  Synopsis [Manipulating list of cubes in the cover.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - February 1, 2003.]
14 
15  Revision [$Id: mvcList.c,v 1.4 2003/04/03 06:31:50 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "mvc.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// FUNCTION DEFINITIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 /**Function*************************************************************
33 
34  Synopsis []
35 
36  Description []
37 
38  SideEffects []
39 
40  SeeAlso []
41 
42 ***********************************************************************/
43 void Mvc_ListAddCubeHead_( Mvc_List_t * pList, Mvc_Cube_t * pCube )
44 {
45  if ( pList->pHead == NULL )
46  {
47  Mvc_CubeSetNext( pCube, NULL );
48  pList->pHead = pCube;
49  pList->pTail = pCube;
50  }
51  else
52  {
53  Mvc_CubeSetNext( pCube, pList->pHead );
54  pList->pHead = pCube;
55  }
56  pList->nItems++;
57 }
58 
59 
60 /**Function*************************************************************
61 
62  Synopsis []
63 
64  Description []
65 
66  SideEffects []
67 
68  SeeAlso []
69 
70 ***********************************************************************/
71 void Mvc_ListAddCubeTail_( Mvc_List_t * pList, Mvc_Cube_t * pCube )
72 {
73  if ( pList->pHead == NULL )
74  pList->pHead = pCube;
75  else
76  Mvc_CubeSetNext( pList->pTail, pCube );
77  pList->pTail = pCube;
78  Mvc_CubeSetNext( pCube, NULL );
79  pList->nItems++;
80 }
81 
82 
83 /**Function*************************************************************
84 
85  Synopsis []
86 
87  Description []
88 
89  SideEffects []
90 
91  SeeAlso []
92 
93 ***********************************************************************/
94 void Mvc_ListDeleteCube_( Mvc_List_t * pList, Mvc_Cube_t * pPrev, Mvc_Cube_t * pCube )
95 {
96  if ( pPrev == NULL ) // deleting the head cube
97  pList->pHead = Mvc_CubeReadNext(pCube);
98  else
99  pPrev->pNext = pCube->pNext;
100  if ( pList->pTail == pCube ) // deleting the tail cube
101  {
102  assert( Mvc_CubeReadNext(pCube) == NULL );
103  pList->pTail = pPrev;
104  }
105  pList->nItems--;
106 }
107 
108 
109 
110 /**Function*************************************************************
111 
112  Synopsis []
113 
114  Description []
115 
116  SideEffects []
117 
118  SeeAlso []
119 
120 ***********************************************************************/
122 {
123  Mvc_List_t * pList = &pCover->lCubes;
124  if ( pList->pHead == NULL )
125  {
126  Mvc_CubeSetNext( pCube, NULL );
127  pList->pHead = pCube;
128  pList->pTail = pCube;
129  }
130  else
131  {
132  Mvc_CubeSetNext( pCube, pList->pHead );
133  pList->pHead = pCube;
134  }
135  pList->nItems++;
136 }
137 
138 /**Function*************************************************************
139 
140  Synopsis []
141 
142  Description []
143 
144  SideEffects []
145 
146  SeeAlso []
147 
148 ***********************************************************************/
150 {
151  Mvc_List_t * pList = &pCover->lCubes;
152 
153  if ( pList->pHead == NULL )
154  pList->pHead = pCube;
155  else
156  Mvc_CubeSetNext( pList->pTail, pCube );
157  pList->pTail = pCube;
158  Mvc_CubeSetNext( pCube, NULL );
159  pList->nItems++;
160 }
161 
162 /**Function*************************************************************
163 
164  Synopsis []
165 
166  Description []
167 
168  SideEffects []
169 
170  SeeAlso []
171 
172 ***********************************************************************/
173 void Mvc_CoverDeleteCube_( Mvc_Cover_t * pCover, Mvc_Cube_t * pPrev, Mvc_Cube_t * pCube )
174 {
175  Mvc_List_t * pList = &pCover->lCubes;
176 
177  if ( pPrev == NULL ) // deleting the head cube
178  pList->pHead = Mvc_CubeReadNext(pCube);
179  else
180  pPrev->pNext = pCube->pNext;
181  if ( pList->pTail == pCube ) // deleting the tail cube
182  {
183  assert( Mvc_CubeReadNext(pCube) == NULL );
184  pList->pTail = pPrev;
185  }
186  pList->nItems--;
187 }
188 
189 
190 
191 /**Function*************************************************************
192 
193  Synopsis []
194 
195  Description []
196 
197  SideEffects []
198 
199  SeeAlso []
200 
201 ***********************************************************************/
203 {
204  Mvc_Cube_t * pCubeNew;
205  pCubeNew = Mvc_CubeAlloc( pCover );
206  Mvc_CubeBitCopy( pCubeNew, pCube );
207  Mvc_CoverAddCubeHead( pCover, pCubeNew );
208 }
209 
210 /**Function*************************************************************
211 
212  Synopsis []
213 
214  Description []
215 
216  SideEffects []
217 
218  SeeAlso []
219 
220 ***********************************************************************/
222 {
223  Mvc_Cube_t * pCubeNew;
224  // copy the cube as part of this cover
225  pCubeNew = Mvc_CubeAlloc( pCover );
226  Mvc_CubeBitCopy( pCubeNew, pCube );
227  // clean the last bits of the new cube
228 // pCubeNew->pData[pCubeNew->iLast] &= (BITS_FULL >> pCubeNew->nUnused);
229  // add the cube at the end
230  Mvc_CoverAddCubeTail( pCover, pCubeNew );
231 }
232 
233 
234 /**Function*************************************************************
235 
236  Synopsis []
237 
238  Description []
239 
240  SideEffects []
241 
242  SeeAlso []
243 
244 ***********************************************************************/
246 {
247 // int iBit, Value;
248 // assert( pCover->pLits );
249 // Mvc_CubeForEachBit( pCover, pCube, iBit, Value )
250 // if ( Value )
251 // pCover->pLits[iBit] += Value;
252 }
253 
254 /**Function*************************************************************
255 
256  Synopsis []
257 
258  Description []
259 
260  SideEffects []
261 
262  SeeAlso []
263 
264 ***********************************************************************/
266 {
267 // int iBit, Value;
268 // assert( pCover->pLits );
269 // Mvc_CubeForEachBit( pCover, pCube, iBit, Value )
270 // if ( Value )
271 // pCover->pLits[iBit] -= Value;
272 }
273 
274 
275 /**Function*************************************************************
276 
277  Synopsis [Transfers the cubes from the list into the array.]
278 
279  Description []
280 
281  SideEffects []
282 
283  SeeAlso []
284 
285 ***********************************************************************/
287 {
288  Mvc_Cube_t * pCube;
289  int Counter;
290  // resize storage if necessary
291  Mvc_CoverAllocateArrayCubes( pCover );
292  // iterate through the cubes
293  Counter = 0;
294  Mvc_CoverForEachCube( pCover, pCube )
295  pCover->pCubes[ Counter++ ] = pCube;
296  assert( Counter == Mvc_CoverReadCubeNum(pCover) );
297 }
298 
299 /**Function*************************************************************
300 
301  Synopsis [Transfers the cubes from the array into list.]
302 
303  Description []
304 
305  SideEffects []
306 
307  SeeAlso []
308 
309 ***********************************************************************/
311 {
312  Mvc_Cube_t * pCube;
313  int nCubes, i;
314 
315  assert( pCover->pCubes );
316 
317  nCubes = Mvc_CoverReadCubeNum(pCover);
318  if ( nCubes == 0 )
319  return;
320  if ( nCubes == 1 )
321  {
322  pCube = pCover->pCubes[0];
323  pCube->pNext = NULL;
324  pCover->lCubes.pHead = pCover->lCubes.pTail = pCube;
325  return;
326  }
327  // set up the first cube
328  pCube = pCover->pCubes[0];
329  pCover->lCubes.pHead = pCube;
330  // set up the last cube
331  pCube = pCover->pCubes[nCubes-1];
332  pCube->pNext = NULL;
333  pCover->lCubes.pTail = pCube;
334 
335  // link all cubes starting from the first one
336  for ( i = 0; i < nCubes - 1; i++ )
337  pCover->pCubes[i]->pNext = pCover->pCubes[i+1];
338 }
339 
340 /**Function*************************************************************
341 
342  Synopsis [Returns the tail of the linked list given by the head.]
343 
344  Description []
345 
346  SideEffects []
347 
348  SeeAlso []
349 
350 ***********************************************************************/
352 {
353  Mvc_Cube_t * pCube, * pTail;
354  for ( pTail = pCube = pHead;
355  pCube;
356  pTail = pCube, pCube = Mvc_CubeReadNext(pCube) );
357  return pTail;
358 }
359 
360 
361 ////////////////////////////////////////////////////////////////////////
362 /// END OF FILE ///
363 ////////////////////////////////////////////////////////////////////////
364 
365 
367 
#define Mvc_CoverAddCubeTail(pCover, pCube)
Definition: mvc.h:501
Mvc_Cube_t ** pCubes
Definition: mvc.h:89
#define Mvc_CubeReadNext(Cube)
MACRO DEFINITIONS ///.
Definition: mvc.h:121
void Mvc_CoverArray2List(Mvc_Cover_t *pCover)
Definition: mvcList.c:310
void Mvc_CoverDeleteLiteralsOfCube(Mvc_Cover_t *pCover, Mvc_Cube_t *pCube)
Definition: mvcList.c:265
void Mvc_CoverList2Array(Mvc_Cover_t *pCover)
Definition: mvcList.c:286
#define Mvc_CoverAddCubeHead(pCover, pCube)
Definition: mvc.h:496
int nItems
Definition: mvc.h:79
Mvc_Cube_t * Mvc_CubeAlloc(Mvc_Cover_t *pCover)
DECLARATIONS ///.
Definition: mvcCube.c:43
void Mvc_CoverAddDupCubeTail(Mvc_Cover_t *pCover, Mvc_Cube_t *pCube)
Definition: mvcList.c:221
Mvc_Cube_t * Mvc_ListGetTailFromHead(Mvc_Cube_t *pHead)
Definition: mvcList.c:351
int Mvc_CoverReadCubeNum(Mvc_Cover_t *pCover)
Definition: mvcApi.c:45
Mvc_List_t lCubes
Definition: mvc.h:88
Mvc_Cube_t * pNext
Definition: mvc.h:65
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int Counter
Mvc_Cube_t * pTail
Definition: mvc.h:78
#define Mvc_CoverForEachCube(Cover, Cube)
Definition: mvc.h:528
#define Mvc_CubeBitCopy(Cube1, Cube2)
Definition: mvc.h:393
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Mvc_Cube_t * pHead
Definition: mvc.h:77
void Mvc_CoverAddDupCubeHead(Mvc_Cover_t *pCover, Mvc_Cube_t *pCube)
Definition: mvcList.c:202
void Mvc_CoverDeleteCube_(Mvc_Cover_t *pCover, Mvc_Cube_t *pPrev, Mvc_Cube_t *pCube)
Definition: mvcList.c:173
void Mvc_CoverAddLiteralsOfCube(Mvc_Cover_t *pCover, Mvc_Cube_t *pCube)
Definition: mvcList.c:245
void Mvc_CoverAllocateArrayCubes(Mvc_Cover_t *pCover)
Definition: mvcCover.c:202
#define Mvc_CubeSetNext(Cube, Next)
Definition: mvc.h:126
void Mvc_ListAddCubeTail_(Mvc_List_t *pList, Mvc_Cube_t *pCube)
Definition: mvcList.c:71
#define assert(ex)
Definition: util_old.h:213
void Mvc_CoverAddCubeTail_(Mvc_Cover_t *pCover, Mvc_Cube_t *pCube)
Definition: mvcList.c:149
void Mvc_CoverAddCubeHead_(Mvc_Cover_t *pCover, Mvc_Cube_t *pCube)
Definition: mvcList.c:121
void Mvc_ListDeleteCube_(Mvc_List_t *pList, Mvc_Cube_t *pPrev, Mvc_Cube_t *pCube)
Definition: mvcList.c:94
ABC_NAMESPACE_IMPL_START void Mvc_ListAddCubeHead_(Mvc_List_t *pList, Mvc_Cube_t *pCube)
DECLARATIONS ///.
Definition: mvcList.c:43