src/misc/mvc/mvcSort.c File Reference

#include "mvc.h"
Include dependency graph for mvcSort.c:

Go to the source code of this file.

Functions

Mvc_Cube_tMvc_CoverSort_rec (Mvc_Cube_t *pList, int nItems, Mvc_Cube_t *pMask, int(*pCompareFunc)(Mvc_Cube_t *, Mvc_Cube_t *, Mvc_Cube_t *))
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 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 44 of file mvcSort.c.

00045 {
00046     Mvc_Cube_t * pHead;
00047     int nCubes;
00048     // one cube does not need sorting
00049     nCubes = Mvc_CoverReadCubeNum(pCover);
00050     if ( nCubes <= 1 )
00051         return;
00052     // sort the cubes 
00053     pHead = Mvc_CoverSort_rec( Mvc_CoverReadCubeHead(pCover), nCubes, pMask, pCompareFunc ); 
00054     // insert the sorted list into the cover
00055     Mvc_CoverSetCubeHead( pCover, pHead );
00056     Mvc_CoverSetCubeTail( pCover, Mvc_ListGetTailFromHead(pHead) );
00057     // make sure that the list is sorted in the increasing order
00058     assert( pCompareFunc( Mvc_CoverReadCubeHead(pCover), Mvc_CoverReadCubeTail(pCover), pMask ) <= 0 );
00059 }

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 
)

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

] DECLARATIONS ///

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

Synopsis [Recursive part of Mvc_CoverSort()]

Description []

SideEffects []

SeeAlso []

Definition at line 72 of file mvcSort.c.

00073 {
00074     Mvc_Cube_t * pList1, * pList2;
00075     int nItems1, nItems2, i;
00076 
00077     // trivial case
00078     if ( nItems == 1 )
00079     {
00080         Mvc_CubeSetNext( pList, NULL );
00081         return pList;
00082     }
00083 
00084     // select the new sizes
00085     nItems1 = nItems/2;
00086     nItems2 = nItems - nItems1;
00087 
00088     // set the new beginnings
00089     pList1 = pList2 = pList;
00090     for ( i = 0; i < nItems1; i++ )
00091         pList2 = Mvc_CubeReadNext( pList2 );
00092 
00093     // solve recursively
00094     pList1 = Mvc_CoverSort_rec( pList1, nItems1, pMask, pCompareFunc );
00095     pList2 = Mvc_CoverSort_rec( pList2, nItems2, pMask, pCompareFunc );
00096 
00097     // merge
00098     return Mvc_CoverSortMerge( pList1, pList2, pMask, pCompareFunc );
00099 }

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 113 of file mvcSort.c.

00114 {
00115     Mvc_Cube_t * pList = NULL, ** ppTail = &pList;
00116     Mvc_Cube_t * pCube;
00117     while ( pList1 && pList2 )
00118     {
00119         if ( pCompareFunc( pList1, pList2, pMask ) < 0 )
00120         {
00121             pCube = pList1;
00122             pList1 = Mvc_CubeReadNext(pList1);
00123         }
00124         else
00125         {
00126             pCube = pList2;
00127             pList2 = Mvc_CubeReadNext(pList2);
00128         }
00129         *ppTail = pCube;
00130         ppTail = Mvc_CubeReadNextP(pCube);
00131     }
00132     *ppTail = pList1? pList1: pList2;
00133     return pList;
00134 }


Generated on Tue Jan 5 12:19:17 2010 for abc70930 by  doxygen 1.6.1