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

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START
Mvc_Cube_t
Mvc_CoverSort_rec (Mvc_Cube_t *pList, int nItems, Mvc_Cube_t *pMask, int(*pCompareFunc)(Mvc_Cube_t *, Mvc_Cube_t *, Mvc_Cube_t *))
 DECLARATIONS ///. More...
 
Mvc_Cube_tMvc_CoverSortMerge (Mvc_Cube_t *pList1, Mvc_Cube_t *pList2, Mvc_Cube_t *pMask, int(*pCompareFunc)(Mvc_Cube_t *, Mvc_Cube_t *, Mvc_Cube_t *))
 
void Mvc_CoverSort (Mvc_Cover_t *pCover, Mvc_Cube_t *pMask, int(*pCompareFunc)(Mvc_Cube_t *, Mvc_Cube_t *, Mvc_Cube_t *))
 FuNCTION DEFINITIONS ///. More...
 

Function Documentation

void Mvc_CoverSort ( Mvc_Cover_t pCover,
Mvc_Cube_t pMask,
int(*)(Mvc_Cube_t *, Mvc_Cube_t *, Mvc_Cube_t *)  pCompareFunc 
)

FuNCTION DEFINITIONS ///.

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

Synopsis [Sorts cubes using the given cost function.]

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file mvcSort.c.

48 {
49  Mvc_Cube_t * pHead;
50  int nCubes;
51  // one cube does not need sorting
52  nCubes = Mvc_CoverReadCubeNum(pCover);
53  if ( nCubes <= 1 )
54  return;
55  // sort the cubes
56  pHead = Mvc_CoverSort_rec( Mvc_CoverReadCubeHead(pCover), nCubes, pMask, pCompareFunc );
57  // insert the sorted list into the cover
58  Mvc_CoverSetCubeHead( pCover, pHead );
60  // make sure that the list is sorted in the increasing order
61  assert( pCompareFunc( Mvc_CoverReadCubeHead(pCover), Mvc_CoverReadCubeTail(pCover), pMask ) <= 0 );
62 }
Mvc_Cube_t * Mvc_CoverReadCubeTail(Mvc_Cover_t *pCover)
Definition: mvcApi.c:47
void Mvc_CoverSetCubeTail(Mvc_Cover_t *pCover, Mvc_Cube_t *pCube)
Definition: mvcApi.c:79
int Mvc_CoverReadCubeNum(Mvc_Cover_t *pCover)
Definition: mvcApi.c:45
void Mvc_CoverSetCubeHead(Mvc_Cover_t *pCover, Mvc_Cube_t *pCube)
Definition: mvcApi.c:78
Mvc_Cube_t * Mvc_ListGetTailFromHead(Mvc_Cube_t *pHead)
Definition: mvcList.c:351
ABC_NAMESPACE_IMPL_START Mvc_Cube_t * Mvc_CoverSort_rec(Mvc_Cube_t *pList, int nItems, Mvc_Cube_t *pMask, int(*pCompareFunc)(Mvc_Cube_t *, Mvc_Cube_t *, Mvc_Cube_t *))
DECLARATIONS ///.
Definition: mvcSort.c:75
#define assert(ex)
Definition: util_old.h:213
Mvc_Cube_t * Mvc_CoverReadCubeHead(Mvc_Cover_t *pCover)
Definition: mvcApi.c:46
Mvc_Cube_t * Mvc_CoverSort_rec ( Mvc_Cube_t pList,
int  nItems,
Mvc_Cube_t pMask,
int(*)(Mvc_Cube_t *, Mvc_Cube_t *, Mvc_Cube_t *)  pCompareFunc 
)

DECLARATIONS ///.

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

FileName [mvcSort.c]

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

Synopsis [Sorting cubes in the cover with the mask.]

Author [MVSIS Group]

Affiliation [uC Berkeley]

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

Revision [

Id:
mvcSort.c,v 1.5 2003/04/27 01:03:45 wjiang Exp

]

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

Synopsis [Recursive part of Mvc_CoverSort()]

Description []

SideEffects []

SeeAlso []

Definition at line 75 of file mvcSort.c.

76 {
77  Mvc_Cube_t * pList1, * pList2;
78  int nItems1, nItems2, i;
79 
80  // trivial case
81  if ( nItems == 1 )
82  {
83  Mvc_CubeSetNext( pList, NULL );
84  return pList;
85  }
86 
87  // select the new sizes
88  nItems1 = nItems/2;
89  nItems2 = nItems - nItems1;
90 
91  // set the new beginnings
92  pList1 = pList2 = pList;
93  for ( i = 0; i < nItems1; i++ )
94  pList2 = Mvc_CubeReadNext( pList2 );
95 
96  // solve recursively
97  pList1 = Mvc_CoverSort_rec( pList1, nItems1, pMask, pCompareFunc );
98  pList2 = Mvc_CoverSort_rec( pList2, nItems2, pMask, pCompareFunc );
99 
100  // merge
101  return Mvc_CoverSortMerge( pList1, pList2, pMask, pCompareFunc );
102 }
#define Mvc_CubeReadNext(Cube)
MACRO DEFINITIONS ///.
Definition: mvc.h:121
ABC_NAMESPACE_IMPL_START Mvc_Cube_t * Mvc_CoverSort_rec(Mvc_Cube_t *pList, int nItems, Mvc_Cube_t *pMask, int(*pCompareFunc)(Mvc_Cube_t *, Mvc_Cube_t *, Mvc_Cube_t *))
DECLARATIONS ///.
Definition: mvcSort.c:75
Mvc_Cube_t * Mvc_CoverSortMerge(Mvc_Cube_t *pList1, Mvc_Cube_t *pList2, Mvc_Cube_t *pMask, int(*pCompareFunc)(Mvc_Cube_t *, Mvc_Cube_t *, Mvc_Cube_t *))
Definition: mvcSort.c:116
#define Mvc_CubeSetNext(Cube, Next)
Definition: mvc.h:126
Mvc_Cube_t * Mvc_CoverSortMerge ( Mvc_Cube_t pList1,
Mvc_Cube_t pList2,
Mvc_Cube_t pMask,
int(*)(Mvc_Cube_t *, Mvc_Cube_t *, Mvc_Cube_t *)  pCompareFunc 
)

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

Synopsis [Merges two NULL-terminated linked lists.]

Description []

SideEffects []

SeeAlso []

Definition at line 116 of file mvcSort.c.

117 {
118  Mvc_Cube_t * pList = NULL, ** ppTail = &pList;
119  Mvc_Cube_t * pCube;
120  while ( pList1 && pList2 )
121  {
122  if ( pCompareFunc( pList1, pList2, pMask ) < 0 )
123  {
124  pCube = pList1;
125  pList1 = Mvc_CubeReadNext(pList1);
126  }
127  else
128  {
129  pCube = pList2;
130  pList2 = Mvc_CubeReadNext(pList2);
131  }
132  *ppTail = pCube;
133  ppTail = Mvc_CubeReadNextP(pCube);
134  }
135  *ppTail = pList1? pList1: pList2;
136  return pList;
137 }
#define Mvc_CubeReadNext(Cube)
MACRO DEFINITIONS ///.
Definition: mvc.h:121
#define Mvc_CubeReadNextP(Cube)
Definition: mvc.h:122