summaryrefslogtreecommitdiffstats
path: root/src/misc/mvc/mvcList.c
blob: 1b39dfbb19f6d805d2addfa113f9f408c77b5f0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/**CFile****************************************************************

  FileName    [mvcList.c]

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

  Synopsis    [Manipulating list of cubes in the cover.]

  Author      [MVSIS Group]
  
  Affiliation [UC Berkeley]

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

  Revision    [$Id: mvcList.c,v 1.4 2003/04/03 06:31:50 alanmi Exp $]

***********************************************************************/

#include "mvc.h"

ABC_NAMESPACE_IMPL_START


////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mvc_ListAddCubeHead_( Mvc_List_t * pList, Mvc_Cube_t * pCube )
{
    if ( pList->pHead == NULL )
    {
        Mvc_CubeSetNext( pCube, NULL );
        pList->pHead = pCube;
        pList->pTail = pCube;
    }
    else
    {
        Mvc_CubeSetNext( pCube, pList->pHead );
        pList->pHead = pCube;
    }
    pList->nItems++;
}


/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mvc_ListAddCubeTail_( Mvc_List_t * pList, Mvc_Cube_t * pCube )
{
    if ( pList->pHead == NULL )
        pList->pHead = pCube;
    else
        Mvc_CubeSetNext( pList->pTail, pCube );
    pList->pTail    = pCube;
    Mvc_CubeSetNext( pCube, NULL );
    pList->nItems++;
}


/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mvc_ListDeleteCube_( Mvc_List_t * pList, Mvc_Cube_t * pPrev, Mvc_Cube_t * pCube )
{
    if ( pPrev == NULL ) // deleting the head cube
        pList->pHead = Mvc_CubeReadNext(pCube);
    else
        pPrev->pNext = pCube->pNext;
    if ( pList->pTail == pCube ) // deleting the tail cube
    {
        assert( Mvc_CubeReadNext(pCube) == NULL );
        pList->pTail = pPrev;
    }
    pList->nItems--;
}



/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mvc_CoverAddCubeHead_( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube )
{
    Mvc_List_t * pList = &pCover->lCubes;
    if ( pList->pHead == NULL )
    {
        Mvc_CubeSetNext( pCube, NULL );
        pList->pHead = pCube;
        pList->pTail = pCube;
    }
    else
    {
        Mvc_CubeSetNext( pCube, pList->pHead );
        pList->pHead = pCube;
    }
    pList->nItems++;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mvc_CoverAddCubeTail_( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube )
{
    Mvc_List_t * pList = &pCover->lCubes;

    if ( pList->pHead == NULL )
        pList->pHead = pCube;
    else
        Mvc_CubeSetNext( pList->pTail, pCube );
    pList->pTail    = pCube;
    Mvc_CubeSetNext( pCube, NULL );
    pList->nItems++;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mvc_CoverDeleteCube_( Mvc_Cover_t * pCover, Mvc_Cube_t * pPrev, Mvc_Cube_t * pCube )
{
    Mvc_List_t * pList = &pCover->lCubes;
 
    if ( pPrev == NULL ) // deleting the head cube
        pList->pHead = Mvc_CubeReadNext(pCube);
    else
        pPrev->pNext = pCube->pNext;
    if ( pList->pTail == pCube ) // deleting the tail cube
    {
        assert( Mvc_CubeReadNext(pCube) == NULL );
        pList->pTail = pPrev;
    }
    pList->nItems--;
}



/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mvc_CoverAddDupCubeHead( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube )
{
    Mvc_Cube_t * pCubeNew;
    pCubeNew = Mvc_CubeAlloc( pCover );
    Mvc_CubeBitCopy( pCubeNew, pCube );
    Mvc_CoverAddCubeHead( pCover, pCubeNew );
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mvc_CoverAddDupCubeTail( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube )
{
    Mvc_Cube_t * pCubeNew;
    // copy the cube as part of this cover
    pCubeNew = Mvc_CubeAlloc( pCover );
    Mvc_CubeBitCopy( pCubeNew, pCube );
    // clean the last bits of the new cube
//    pCubeNew->pData[pCubeNew->iLast] &= (BITS_FULL >> pCubeNew->nUnused);
    // add the cube at the end
    Mvc_CoverAddCubeTail( pCover, pCubeNew );
}


/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mvc_CoverAddLiteralsOfCube( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube )
{
//    int iBit, Value;
//    assert( pCover->pLits );
//    Mvc_CubeForEachBit( pCover, pCube, iBit, Value )
//        if ( Value )
//            pCover->pLits[iBit] += Value;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mvc_CoverDeleteLiteralsOfCube( Mvc_Cover_t * pCover, Mvc_Cube_t * pCube )
{
//    int iBit, Value;
//    assert( pCover->pLits );
//    Mvc_CubeForEachBit( pCover, pCube, iBit, Value )
//        if ( Value )
//            pCover->pLits[iBit] -= Value;
}


/**Function*************************************************************

  Synopsis    [Transfers the cubes from the list into the array.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mvc_CoverList2Array( Mvc_Cover_t * pCover )
{
    Mvc_Cube_t * pCube;
    int Counter;
    // resize storage if necessary
    Mvc_CoverAllocateArrayCubes( pCover );
    // iterate through the cubes
    Counter = 0;
    Mvc_CoverForEachCube( pCover, pCube )
        pCover->pCubes[ Counter++ ] = pCube;
    assert( Counter == Mvc_CoverReadCubeNum(pCover) );
}

/**Function*************************************************************

  Synopsis    [Transfers the cubes from the array into list.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mvc_CoverArray2List( Mvc_Cover_t * pCover )
{
    Mvc_Cube_t * pCube;
    int nCubes, i;

    assert( pCover->pCubes );

    nCubes = Mvc_CoverReadCubeNum(pCover);
    if ( nCubes == 0 )
        return;
    if ( nCubes == 1 )
    {
        pCube    = pCover->pCubes[0];
        pCube->pNext = NULL;
        pCover->lCubes.pHead = pCover->lCubes.pTail = pCube;
        return;
    }
    // set up the first cube
    pCube = pCover->pCubes[0];
    pCover->lCubes.pHead = pCube;
    // set up the last cube
    pCube = pCover->pCubes[nCubes-1];
    pCube->pNext = NULL;
    pCover->lCubes.pTail = pCube;

    // link all cubes starting from the first one
    for ( i = 0; i < nCubes - 1; i++ )
        pCover->pCubes[i]->pNext = pCover->pCubes[i+1];
}

/**Function*************************************************************

  Synopsis    [Returns the tail of the linked list given by the head.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Mvc_Cube_t * Mvc_ListGetTailFromHead( Mvc_Cube_t * pHead )
{
    Mvc_Cube_t * pCube, * pTail;
    for ( pTail = pCube = pHead; 
          pCube; 
          pTail = pCube, pCube = Mvc_CubeReadNext(pCube) );
    return pTail;
}


////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


ABC_NAMESPACE_IMPL_END