ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
utilSort.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "abc_global.h"
Include dependency graph for utilSort.c:

Go to the source code of this file.

Macros

#define NUMBER1   3716960521u
 
#define NUMBER2   2174103536u
 

Functions

ABC_NAMESPACE_IMPL_START void Abc_SortMerge (int *p1Beg, int *p1End, int *p2Beg, int *p2End, int *pOut)
 DECLARATIONS ///.
 
void Abc_Sort_rec (int *pInBeg, int *pInEnd, int *pOutBeg)
 
void Abc_MergeSort (int *pInput, int nSize)
 
void Abc_SortMergeCost2 (int *p1Beg, int *p1End, int *p2Beg, int *p2End, int *pOut, int *pCost)
 
void Abc_SortCost2_rec (int *pInBeg, int *pInEnd, int *pOutBeg, int *pCost)
 
void Abc_MergeSortCost2 (int *pInput, int nSize, int *pCost)
 
void Abc_SortMergeCost2Reverse (int *p1Beg, int *p1End, int *p2Beg, int *p2End, int *pOut, int *pCost)
 
void Abc_SortCost2Reverse_rec (int *pInBeg, int *pInEnd, int *pOutBeg, int *pCost)
 
void Abc_MergeSortCost2Reverse (int *pInput, int nSize, int *pCost)
 
void Abc_MergeSortCostMerge (int *p1Beg, int *p1End, int *p2Beg, int *p2End, int *pOut)
 
void Abc_MergeSortCost_rec (int *pInBeg, int *pInEnd, int *pOutBeg)
 
int * Abc_MergeSortCost (int *pCosts, int nSize)
 
int Abc_SortNumCompare (int *pNum1, int *pNum2)
 
void Abc_SortTest ()
 
int Abc_QuickSort1CompareInc (word *p1, word *p2)
 
int Abc_QuickSort1CompareDec (word *p1, word *p2)
 
void Abc_QuickSort1 (word *pData, int nSize, int fDecrease)
 
void Abc_QuickSort2Inc_rec (word *pData, int l, int r)
 
void Abc_QuickSort2Dec_rec (word *pData, int l, int r)
 
void Abc_QuickSort3Inc_rec (word *pData, int l, int r)
 
void Abc_QuickSort3Dec_rec (word *pData, int l, int r)
 
void Abc_QuickSort2 (word *pData, int nSize, int fDecrease)
 
void Abc_QuickSort3 (word *pData, int nSize, int fDecrease)
 
void Abc_QuickSortCostData (int *pCosts, int nSize, int fDecrease, word *pData, int *pResult)
 
int * Abc_QuickSortCost (int *pCosts, int nSize, int fDecrease)
 
void Abc_QuickSortTest ()
 
unsigned Abc_Random (int fReset)
 
word Abc_RandomW (int fReset)
 

Macro Definition Documentation

◆ NUMBER1

#define NUMBER1   3716960521u

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 1001 of file utilSort.c.

◆ NUMBER2

#define NUMBER2   2174103536u

Definition at line 1002 of file utilSort.c.

Function Documentation

◆ Abc_MergeSort()

void Abc_MergeSort ( int * pInput,
int nSize )

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

Synopsis [Returns the sorted array of integers.]

Description [This procedure is about 10% faster than qsort().]

SideEffects []

SeeAlso []

Definition at line 129 of file utilSort.c.

130{
131 int * pOutput;
132 if ( nSize < 2 )
133 return;
134 pOutput = (int *) malloc( sizeof(int) * nSize );
135 Abc_Sort_rec( pInput, pInput + nSize, pOutput );
136 free( pOutput );
137}
void Abc_Sort_rec(int *pInBeg, int *pInEnd, int *pOutBeg)
Definition utilSort.c:80
VOID_HACK free()
char * malloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_MergeSortCost()

int * Abc_MergeSortCost ( int * pCosts,
int nSize )

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

Synopsis [Sorting procedure.]

Description [Returns permutation for the non-decreasing order of costs.]

SideEffects []

SeeAlso []

Definition at line 442 of file utilSort.c.

443{
444 int i, * pResult, * pInput, * pOutput;
445 pResult = (int *) calloc( sizeof(int), nSize );
446 if ( nSize < 2 )
447 return pResult;
448 pInput = (int *) malloc( sizeof(int) * 2 * nSize );
449 pOutput = (int *) malloc( sizeof(int) * 2 * nSize );
450 for ( i = 0; i < nSize; i++ )
451 pInput[2*i] = i, pInput[2*i+1] = pCosts[i];
452 Abc_MergeSortCost_rec( pInput, pInput + 2*nSize, pOutput );
453 for ( i = 0; i < nSize; i++ )
454 pResult[i] = pInput[2*i];
455 free( pOutput );
456 free( pInput );
457 return pResult;
458}
void Abc_MergeSortCost_rec(int *pInBeg, int *pInEnd, int *pOutBeg)
Definition utilSort.c:387
char * calloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_MergeSortCost2()

void Abc_MergeSortCost2 ( int * pInput,
int nSize,
int * pCost )

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

Synopsis [Returns the sorted array of integers.]

Description [This procedure is about 10% faster than qsort().]

SideEffects []

SeeAlso []

Definition at line 231 of file utilSort.c.

232{
233 int * pOutput;
234 if ( nSize < 2 )
235 return;
236 pOutput = (int *) malloc( sizeof(int) * nSize );
237 Abc_SortCost2_rec( pInput, pInput + nSize, pOutput, pCost );
238 free( pOutput );
239}
void Abc_SortCost2_rec(int *pInBeg, int *pInEnd, int *pOutBeg, int *pCost)
Definition utilSort.c:182
Here is the call graph for this function:

◆ Abc_MergeSortCost2Reverse()

void Abc_MergeSortCost2Reverse ( int * pInput,
int nSize,
int * pCost )

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

Synopsis [Returns the sorted array of integers.]

Description [This procedure is about 10% faster than qsort().]

SideEffects []

SeeAlso []

Definition at line 333 of file utilSort.c.

334{
335 int * pOutput;
336 if ( nSize < 2 )
337 return;
338 pOutput = (int *) malloc( sizeof(int) * nSize );
339 Abc_SortCost2Reverse_rec( pInput, pInput + nSize, pOutput, pCost );
340 free( pOutput );
341}
void Abc_SortCost2Reverse_rec(int *pInBeg, int *pInEnd, int *pOutBeg, int *pCost)
Definition utilSort.c:284
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_MergeSortCost_rec()

void Abc_MergeSortCost_rec ( int * pInBeg,
int * pInEnd,
int * pOutBeg )

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

Synopsis [Recursive sorting.]

Description []

SideEffects []

SeeAlso []

Definition at line 387 of file utilSort.c.

388{
389 int nSize = (pInEnd - pInBeg)/2;
390 assert( nSize > 0 );
391 if ( nSize == 1 )
392 return;
393 if ( nSize == 2 )
394 {
395 if ( pInBeg[1] > pInBeg[3] )
396 {
397 pInBeg[1] ^= pInBeg[3];
398 pInBeg[3] ^= pInBeg[1];
399 pInBeg[1] ^= pInBeg[3];
400 pInBeg[0] ^= pInBeg[2];
401 pInBeg[2] ^= pInBeg[0];
402 pInBeg[0] ^= pInBeg[2];
403 }
404 }
405 else if ( nSize < 8 )
406 {
407 int temp, i, j, best_i;
408 for ( i = 0; i < nSize-1; i++ )
409 {
410 best_i = i;
411 for ( j = i+1; j < nSize; j++ )
412 if ( pInBeg[2*j+1] < pInBeg[2*best_i+1] )
413 best_i = j;
414 temp = pInBeg[2*i];
415 pInBeg[2*i] = pInBeg[2*best_i];
416 pInBeg[2*best_i] = temp;
417 temp = pInBeg[2*i+1];
418 pInBeg[2*i+1] = pInBeg[2*best_i+1];
419 pInBeg[2*best_i+1] = temp;
420 }
421 }
422 else
423 {
424 Abc_MergeSortCost_rec( pInBeg, pInBeg + 2*(nSize/2), pOutBeg );
425 Abc_MergeSortCost_rec( pInBeg + 2*(nSize/2), pInEnd, pOutBeg + 2*(nSize/2) );
426 Abc_MergeSortCostMerge( pInBeg, pInBeg + 2*(nSize/2), pInBeg + 2*(nSize/2), pInEnd, pOutBeg );
427 memcpy( pInBeg, pOutBeg, sizeof(int) * 2 * nSize );
428 }
429}
void Abc_MergeSortCostMerge(int *p1Beg, int *p1End, int *p2Beg, int *p2End, int *pOut)
Definition utilSort.c:356
#define assert(ex)
Definition util_old.h:213
char * memcpy()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_MergeSortCostMerge()

void Abc_MergeSortCostMerge ( int * p1Beg,
int * p1End,
int * p2Beg,
int * p2End,
int * pOut )

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

Synopsis [Merging two lists of entries.]

Description []

SideEffects []

SeeAlso []

Definition at line 356 of file utilSort.c.

357{
358 int nEntries = (p1End - p1Beg) + (p2End - p2Beg);
359 int * pOutBeg = pOut;
360 while ( p1Beg < p1End && p2Beg < p2End )
361 {
362 if ( p1Beg[1] == p2Beg[1] )
363 *pOut++ = *p1Beg++, *pOut++ = *p1Beg++, *pOut++ = *p2Beg++, *pOut++ = *p2Beg++;
364 else if ( p1Beg[1] < p2Beg[1] )
365 *pOut++ = *p1Beg++, *pOut++ = *p1Beg++;
366 else // if ( p1Beg[1] > p2Beg[1] )
367 *pOut++ = *p2Beg++, *pOut++ = *p2Beg++;
368 }
369 while ( p1Beg < p1End )
370 *pOut++ = *p1Beg++, *pOut++ = *p1Beg++;
371 while ( p2Beg < p2End )
372 *pOut++ = *p2Beg++, *pOut++ = *p2Beg++;
373 assert( pOut - pOutBeg == nEntries );
374}
Here is the caller graph for this function:

◆ Abc_QuickSort1()

void Abc_QuickSort1 ( word * pData,
int nSize,
int fDecrease )

Definition at line 681 of file utilSort.c.

682{
683 int i, fVerify = 0;
684 if ( fDecrease )
685 {
686 qsort( (void *)pData, (size_t)nSize, sizeof(word), (int (*)(const void *, const void *))Abc_QuickSort1CompareDec );
687 if ( fVerify )
688 for ( i = 1; i < nSize; i++ )
689 assert( (unsigned)pData[i-1] >= (unsigned)pData[i] );
690 }
691 else
692 {
693 qsort( (void *)pData, (size_t)nSize, sizeof(word), (int (*)(const void *, const void *))Abc_QuickSort1CompareInc );
694 if ( fVerify )
695 for ( i = 1; i < nSize; i++ )
696 assert( (unsigned)pData[i-1] <= (unsigned)pData[i] );
697 }
698}
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int Abc_QuickSort1CompareDec(word *p1, word *p2)
Definition utilSort.c:673
int Abc_QuickSort1CompareInc(word *p1, word *p2)
Definition utilSort.c:665
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_QuickSort1CompareDec()

int Abc_QuickSort1CompareDec ( word * p1,
word * p2 )

Definition at line 673 of file utilSort.c.

674{
675 if ( (unsigned)(*p1) > (unsigned)(*p2) )
676 return -1;
677 if ( (unsigned)(*p1) < (unsigned)(*p2) )
678 return 1;
679 return 0;
680}
Here is the caller graph for this function:

◆ Abc_QuickSort1CompareInc()

int Abc_QuickSort1CompareInc ( word * p1,
word * p2 )

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

Synopsis [QuickSort algorithm as implemented by qsort().]

Description []

SideEffects []

SeeAlso []

Definition at line 665 of file utilSort.c.

666{
667 if ( (unsigned)(*p1) < (unsigned)(*p2) )
668 return -1;
669 if ( (unsigned)(*p1) > (unsigned)(*p2) )
670 return 1;
671 return 0;
672}
Here is the caller graph for this function:

◆ Abc_QuickSort2()

void Abc_QuickSort2 ( word * pData,
int nSize,
int fDecrease )

Definition at line 866 of file utilSort.c.

867{
868 int i, fVerify = 0;
869 if ( fDecrease )
870 {
871 Abc_QuickSort2Dec_rec( pData, 0, nSize - 1 );
872 if ( fVerify )
873 for ( i = 1; i < nSize; i++ )
874 assert( (unsigned)pData[i-1] >= (unsigned)pData[i] );
875 }
876 else
877 {
878 Abc_QuickSort2Inc_rec( pData, 0, nSize - 1 );
879 if ( fVerify )
880 for ( i = 1; i < nSize; i++ )
881 assert( (unsigned)pData[i-1] <= (unsigned)pData[i] );
882 }
883}
void Abc_QuickSort2Dec_rec(word *pData, int l, int r)
Definition utilSort.c:768
void Abc_QuickSort2Inc_rec(word *pData, int l, int r)
Definition utilSort.c:742
Here is the call graph for this function:

◆ Abc_QuickSort2Dec_rec()

void Abc_QuickSort2Dec_rec ( word * pData,
int l,
int r )

Definition at line 768 of file utilSort.c.

769{
770 word v = pData[r];
771 int i = l-1, j = r;
772 if ( l >= r )
773 return;
774 assert( l < r );
775 if ( r - l < 10 )
776 {
777 Abc_SelectSortDec( pData + l, r - l + 1 );
778 return;
779 }
780 while ( 1 )
781 {
782 while ( (unsigned)pData[++i] > (unsigned)v );
783 while ( (unsigned)v > (unsigned)pData[--j] )
784 if ( j == l )
785 break;
786 if ( i >= j )
787 break;
788 ABC_SWAP( word, pData[i], pData[j] );
789 }
790 ABC_SWAP( word, pData[i], pData[r] );
791 Abc_QuickSort2Dec_rec( pData, l, i-1 );
792 Abc_QuickSort2Dec_rec( pData, i+1, r );
793}
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_QuickSort2Inc_rec()

void Abc_QuickSort2Inc_rec ( word * pData,
int l,
int r )

Definition at line 742 of file utilSort.c.

743{
744 word v = pData[r];
745 int i = l-1, j = r;
746 if ( l >= r )
747 return;
748 assert( l < r );
749 if ( r - l < 10 )
750 {
751 Abc_SelectSortInc( pData + l, r - l + 1 );
752 return;
753 }
754 while ( 1 )
755 {
756 while ( (unsigned)pData[++i] < (unsigned)v );
757 while ( (unsigned)v < (unsigned)pData[--j] )
758 if ( j == l )
759 break;
760 if ( i >= j )
761 break;
762 ABC_SWAP( word, pData[i], pData[j] );
763 }
764 ABC_SWAP( word, pData[i], pData[r] );
765 Abc_QuickSort2Inc_rec( pData, l, i-1 );
766 Abc_QuickSort2Inc_rec( pData, i+1, r );
767}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_QuickSort3()

void Abc_QuickSort3 ( word * pData,
int nSize,
int fDecrease )

Definition at line 884 of file utilSort.c.

885{
886 int i, fVerify = 1;
887 if ( fDecrease )
888 {
889 Abc_QuickSort2Dec_rec( pData, 0, nSize - 1 );
890 if ( fVerify )
891 for ( i = 1; i < nSize; i++ )
892 assert( (unsigned)pData[i-1] >= (unsigned)pData[i] );
893 }
894 else
895 {
896 Abc_QuickSort2Inc_rec( pData, 0, nSize - 1 );
897 if ( fVerify )
898 for ( i = 1; i < nSize; i++ )
899 assert( (unsigned)pData[i-1] <= (unsigned)pData[i] );
900 }
901}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_QuickSort3Dec_rec()

void Abc_QuickSort3Dec_rec ( word * pData,
int l,
int r )

Definition at line 830 of file utilSort.c.

831{
832 word v = pData[r];
833 int k, i = l-1, j = r, p = l-1, q = r;
834 if ( l >= r )
835 return;
836 assert( l < r );
837 if ( r - l < 10 )
838 {
839 Abc_SelectSortDec( pData + l, r - l + 1 );
840 return;
841 }
842 while ( 1 )
843 {
844 while ( (unsigned)pData[++i] > (unsigned)v );
845 while ( (unsigned)v > (unsigned)pData[--j] )
846 if ( j == l )
847 break;
848 if ( i >= j )
849 break;
850 ABC_SWAP( word, pData[i], pData[j] );
851 if ( (unsigned)pData[i] == (unsigned)v )
852 { p++; ABC_SWAP( word, pData[p], pData[i] ); }
853 if ( (unsigned)v == (unsigned)pData[j] )
854 { q--; ABC_SWAP( word, pData[j], pData[q] ); }
855 }
856 ABC_SWAP( word, pData[i], pData[r] );
857 j = i-1; i = i+1;
858 for ( k = l; k < p; k++, j-- )
859 ABC_SWAP( word, pData[k], pData[j] );
860 for ( k = r-1; k > q; k--, i++ )
861 ABC_SWAP( word, pData[i], pData[k] );
862 Abc_QuickSort3Dec_rec( pData, l, j );
863 Abc_QuickSort3Dec_rec( pData, i, r );
864}
Cube * p
Definition exorList.c:222
void Abc_QuickSort3Dec_rec(word *pData, int l, int r)
Definition utilSort.c:830
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_QuickSort3Inc_rec()

void Abc_QuickSort3Inc_rec ( word * pData,
int l,
int r )

Definition at line 795 of file utilSort.c.

796{
797 word v = pData[r];
798 int k, i = l-1, j = r, p = l-1, q = r;
799 if ( l >= r )
800 return;
801 assert( l < r );
802 if ( r - l < 10 )
803 {
804 Abc_SelectSortInc( pData + l, r - l + 1 );
805 return;
806 }
807 while ( 1 )
808 {
809 while ( (unsigned)pData[++i] < (unsigned)v );
810 while ( (unsigned)v < (unsigned)pData[--j] )
811 if ( j == l )
812 break;
813 if ( i >= j )
814 break;
815 ABC_SWAP( word, pData[i], pData[j] );
816 if ( (unsigned)pData[i] == (unsigned)v )
817 { p++; ABC_SWAP( word, pData[p], pData[i] ); }
818 if ( (unsigned)v == (unsigned)pData[j] )
819 { q--; ABC_SWAP( word, pData[j], pData[q] ); }
820 }
821 ABC_SWAP( word, pData[i], pData[r] );
822 j = i-1; i = i+1;
823 for ( k = l; k < p; k++, j-- )
824 ABC_SWAP( word, pData[k], pData[j] );
825 for ( k = r-1; k > q; k--, i++ )
826 ABC_SWAP( word, pData[i], pData[k] );
827 Abc_QuickSort3Inc_rec( pData, l, j );
828 Abc_QuickSort3Inc_rec( pData, i, r );
829}
void Abc_QuickSort3Inc_rec(word *pData, int l, int r)
Definition utilSort.c:795
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_QuickSortCost()

int * Abc_QuickSortCost ( int * pCosts,
int nSize,
int fDecrease )

Definition at line 923 of file utilSort.c.

924{
925 word * pData = ABC_ALLOC( word, nSize );
926 int * pResult = ABC_ALLOC( int, nSize );
927 Abc_QuickSortCostData( pCosts, nSize, fDecrease, pData, pResult );
928 ABC_FREE( pData );
929 return pResult;
930}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
void Abc_QuickSortCostData(int *pCosts, int nSize, int fDecrease, word *pData, int *pResult)
Definition utilSort.c:914
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_QuickSortCostData()

void Abc_QuickSortCostData ( int * pCosts,
int nSize,
int fDecrease,
word * pData,
int * pResult )

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

Synopsis [Wrapper around QuickSort to sort entries based on cost.]

Description []

SideEffects []

SeeAlso []

Definition at line 914 of file utilSort.c.

915{
916 int i;
917 for ( i = 0; i < nSize; i++ )
918 pData[i] = ((word)i << 32) | pCosts[i];
919 Abc_QuickSort3( pData, nSize, fDecrease );
920 for ( i = 0; i < nSize; i++ )
921 pResult[i] = (int)(pData[i] >> 32);
922}
void Abc_QuickSort3(word *pData, int nSize, int fDecrease)
Definition utilSort.c:884
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_QuickSortTest()

void Abc_QuickSortTest ( )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 946 of file utilSort.c.

947{
948 int nSize = 1000000;
949 int fVerbose = 0;
950 word * pData1, * pData2;
951 int i;
952 abctime clk = Abc_Clock();
953 // generate numbers
954 pData1 = ABC_ALLOC( word, nSize );
955 pData2 = ABC_ALLOC( word, nSize );
956 srand( 1111 );
957 for ( i = 0; i < nSize; i++ )
958 pData2[i] = pData1[i] = ((word)i << 32) | rand();
959 Abc_PrintTime( 1, "Prepare ", Abc_Clock() - clk );
960 // perform sorting
961 clk = Abc_Clock();
962 Abc_QuickSort3( pData1, nSize, 1 );
963 Abc_PrintTime( 1, "Sort new", Abc_Clock() - clk );
964 // print the result
965 if ( fVerbose )
966 {
967 for ( i = 0; i < nSize; i++ )
968 printf( "(%d,%d) ", (int)(pData1[i] >> 32), (int)pData1[i] );
969 printf( "\n" );
970 }
971 // create new numbers
972 clk = Abc_Clock();
973 Abc_QuickSort1( pData2, nSize, 1 );
974 Abc_PrintTime( 1, "Sort old", Abc_Clock() - clk );
975 // print the result
976 if ( fVerbose )
977 {
978 for ( i = 0; i < nSize; i++ )
979 printf( "(%d,%d) ", (int)(pData2[i] >> 32), (int)pData2[i] );
980 printf( "\n" );
981 }
982 ABC_FREE( pData1 );
983 ABC_FREE( pData2 );
984}
ABC_INT64_T abctime
Definition abc_global.h:332
void Abc_QuickSort1(word *pData, int nSize, int fDecrease)
Definition utilSort.c:681
Here is the call graph for this function:

◆ Abc_Random()

unsigned Abc_Random ( int fReset)

Definition at line 1004 of file utilSort.c.

1005{
1006#ifdef _MSC_VER
1007 static unsigned int m_z = NUMBER1;
1008 static unsigned int m_w = NUMBER2;
1009#else
1010 static __thread unsigned int m_z = NUMBER1;
1011 static __thread unsigned int m_w = NUMBER2;
1012#endif
1013 if ( fReset )
1014 {
1015 m_z = NUMBER1;
1016 m_w = NUMBER2;
1017 }
1018 m_z = 36969 * (m_z & 65535) + (m_z >> 16);
1019 m_w = 18000 * (m_w & 65535) + (m_w >> 16);
1020 return (m_z << 16) + m_w;
1021}
#define NUMBER2
Definition aigUtil.c:1157
#define NUMBER1
Definition aigUtil.c:1156

◆ Abc_RandomW()

word Abc_RandomW ( int fReset)

Definition at line 1022 of file utilSort.c.

1023{
1024 return ((word)Abc_Random(fReset) << 32) | ((word)Abc_Random(fReset) << 0);
1025}
unsigned Abc_Random(int fReset)
Definition utilSort.c:1004
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_Sort_rec()

void Abc_Sort_rec ( int * pInBeg,
int * pInEnd,
int * pOutBeg )

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

Synopsis [Recursive sorting.]

Description []

SideEffects []

SeeAlso []

Definition at line 80 of file utilSort.c.

81{
82 int nSize = pInEnd - pInBeg;
83 assert( nSize > 0 );
84 if ( nSize == 1 )
85 return;
86 if ( nSize == 2 )
87 {
88 if ( pInBeg[0] > pInBeg[1] )
89 {
90 pInBeg[0] ^= pInBeg[1];
91 pInBeg[1] ^= pInBeg[0];
92 pInBeg[0] ^= pInBeg[1];
93 }
94 }
95 else if ( nSize < 8 )
96 {
97 int temp, i, j, best_i;
98 for ( i = 0; i < nSize-1; i++ )
99 {
100 best_i = i;
101 for ( j = i+1; j < nSize; j++ )
102 if ( pInBeg[j] < pInBeg[best_i] )
103 best_i = j;
104 temp = pInBeg[i];
105 pInBeg[i] = pInBeg[best_i];
106 pInBeg[best_i] = temp;
107 }
108 }
109 else
110 {
111 Abc_Sort_rec( pInBeg, pInBeg + nSize/2, pOutBeg );
112 Abc_Sort_rec( pInBeg + nSize/2, pInEnd, pOutBeg + nSize/2 );
113 Abc_SortMerge( pInBeg, pInBeg + nSize/2, pInBeg + nSize/2, pInEnd, pOutBeg );
114 memcpy( pInBeg, pOutBeg, sizeof(int) * nSize );
115 }
116}
ABC_NAMESPACE_IMPL_START void Abc_SortMerge(int *p1Beg, int *p1End, int *p2Beg, int *p2End, int *pOut)
DECLARATIONS ///.
Definition utilSort.c:49
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_SortCost2_rec()

void Abc_SortCost2_rec ( int * pInBeg,
int * pInEnd,
int * pOutBeg,
int * pCost )

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

Synopsis [Recursive sorting.]

Description []

SideEffects []

SeeAlso []

Definition at line 182 of file utilSort.c.

183{
184 int nSize = pInEnd - pInBeg;
185 assert( nSize > 0 );
186 if ( nSize == 1 )
187 return;
188 if ( nSize == 2 )
189 {
190 if ( pCost[pInBeg[0]] > pCost[pInBeg[1]] )
191 {
192 pInBeg[0] ^= pInBeg[1];
193 pInBeg[1] ^= pInBeg[0];
194 pInBeg[0] ^= pInBeg[1];
195 }
196 }
197 else if ( nSize < 8 )
198 {
199 int temp, i, j, best_i;
200 for ( i = 0; i < nSize-1; i++ )
201 {
202 best_i = i;
203 for ( j = i+1; j < nSize; j++ )
204 if ( pCost[pInBeg[j]] < pCost[pInBeg[best_i]] )
205 best_i = j;
206 temp = pInBeg[i];
207 pInBeg[i] = pInBeg[best_i];
208 pInBeg[best_i] = temp;
209 }
210 }
211 else
212 {
213 Abc_SortCost2_rec( pInBeg, pInBeg + nSize/2, pOutBeg, pCost );
214 Abc_SortCost2_rec( pInBeg + nSize/2, pInEnd, pOutBeg + nSize/2, pCost );
215 Abc_SortMergeCost2( pInBeg, pInBeg + nSize/2, pInBeg + nSize/2, pInEnd, pOutBeg, pCost );
216 memcpy( pInBeg, pOutBeg, sizeof(int) * nSize );
217 }
218}
void Abc_SortMergeCost2(int *p1Beg, int *p1End, int *p2Beg, int *p2End, int *pOut, int *pCost)
Definition utilSort.c:151
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_SortCost2Reverse_rec()

void Abc_SortCost2Reverse_rec ( int * pInBeg,
int * pInEnd,
int * pOutBeg,
int * pCost )

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

Synopsis [Recursive sorting.]

Description []

SideEffects []

SeeAlso []

Definition at line 284 of file utilSort.c.

285{
286 int nSize = pInEnd - pInBeg;
287 assert( nSize > 0 );
288 if ( nSize == 1 )
289 return;
290 if ( nSize == 2 )
291 {
292 if ( pCost[pInBeg[0]] < pCost[pInBeg[1]] )
293 {
294 pInBeg[0] ^= pInBeg[1];
295 pInBeg[1] ^= pInBeg[0];
296 pInBeg[0] ^= pInBeg[1];
297 }
298 }
299 else if ( nSize < 8 )
300 {
301 int temp, i, j, best_i;
302 for ( i = 0; i < nSize-1; i++ )
303 {
304 best_i = i;
305 for ( j = i+1; j < nSize; j++ )
306 if ( pCost[pInBeg[j]] > pCost[pInBeg[best_i]] )
307 best_i = j;
308 temp = pInBeg[i];
309 pInBeg[i] = pInBeg[best_i];
310 pInBeg[best_i] = temp;
311 }
312 }
313 else
314 {
315 Abc_SortCost2Reverse_rec( pInBeg, pInBeg + nSize/2, pOutBeg, pCost );
316 Abc_SortCost2Reverse_rec( pInBeg + nSize/2, pInEnd, pOutBeg + nSize/2, pCost );
317 Abc_SortMergeCost2Reverse( pInBeg, pInBeg + nSize/2, pInBeg + nSize/2, pInEnd, pOutBeg, pCost );
318 memcpy( pInBeg, pOutBeg, sizeof(int) * nSize );
319 }
320}
void Abc_SortMergeCost2Reverse(int *p1Beg, int *p1End, int *p2Beg, int *p2End, int *pOut, int *pCost)
Definition utilSort.c:253
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_SortMerge()

ABC_NAMESPACE_IMPL_START void Abc_SortMerge ( int * p1Beg,
int * p1End,
int * p2Beg,
int * p2End,
int * pOut )

DECLARATIONS ///.

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

FileName [utilSort.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Merge sort with user-specified cost.]

Synopsis [Merge sort with user-specified cost.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - Feburary 13, 2011.]

Revision [

Id
utilSort.c,v 1.00 2011/02/11 00:00:00 alanmi Exp

] FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Merging two lists of entries.]

Description []

SideEffects []

SeeAlso []

Definition at line 49 of file utilSort.c.

50{
51 int nEntries = (p1End - p1Beg) + (p2End - p2Beg);
52 int * pOutBeg = pOut;
53 while ( p1Beg < p1End && p2Beg < p2End )
54 {
55 if ( *p1Beg == *p2Beg )
56 *pOut++ = *p1Beg++, *pOut++ = *p2Beg++;
57 else if ( *p1Beg < *p2Beg )
58 *pOut++ = *p1Beg++;
59 else // if ( *p1Beg > *p2Beg )
60 *pOut++ = *p2Beg++;
61 }
62 while ( p1Beg < p1End )
63 *pOut++ = *p1Beg++;
64 while ( p2Beg < p2End )
65 *pOut++ = *p2Beg++;
66 assert( pOut - pOutBeg == nEntries );
67}
Here is the caller graph for this function:

◆ Abc_SortMergeCost2()

void Abc_SortMergeCost2 ( int * p1Beg,
int * p1End,
int * p2Beg,
int * p2End,
int * pOut,
int * pCost )

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

Synopsis [Merging two lists of entries.]

Description []

SideEffects []

SeeAlso []

Definition at line 151 of file utilSort.c.

152{
153 int nEntries = (p1End - p1Beg) + (p2End - p2Beg);
154 int * pOutBeg = pOut;
155 while ( p1Beg < p1End && p2Beg < p2End )
156 {
157 if ( pCost[*p1Beg] == pCost[*p2Beg] )
158 *pOut++ = *p1Beg++, *pOut++ = *p2Beg++;
159 else if ( pCost[*p1Beg] < pCost[*p2Beg] )
160 *pOut++ = *p1Beg++;
161 else // if ( pCost[*p1Beg] > pCost[*p2Beg] )
162 *pOut++ = *p2Beg++;
163 }
164 while ( p1Beg < p1End )
165 *pOut++ = *p1Beg++;
166 while ( p2Beg < p2End )
167 *pOut++ = *p2Beg++;
168 assert( pOut - pOutBeg == nEntries );
169}
Here is the caller graph for this function:

◆ Abc_SortMergeCost2Reverse()

void Abc_SortMergeCost2Reverse ( int * p1Beg,
int * p1End,
int * p2Beg,
int * p2End,
int * pOut,
int * pCost )

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

Synopsis [Merging two lists of entries.]

Description []

SideEffects []

SeeAlso []

Definition at line 253 of file utilSort.c.

254{
255 int nEntries = (p1End - p1Beg) + (p2End - p2Beg);
256 int * pOutBeg = pOut;
257 while ( p1Beg < p1End && p2Beg < p2End )
258 {
259 if ( pCost[*p1Beg] == pCost[*p2Beg] )
260 *pOut++ = *p1Beg++, *pOut++ = *p2Beg++;
261 else if ( pCost[*p1Beg] > pCost[*p2Beg] )
262 *pOut++ = *p1Beg++;
263 else // if ( pCost[*p1Beg] < pCost[*p2Beg] )
264 *pOut++ = *p2Beg++;
265 }
266 while ( p1Beg < p1End )
267 *pOut++ = *p1Beg++;
268 while ( p2Beg < p2End )
269 *pOut++ = *p2Beg++;
270 assert( pOut - pOutBeg == nEntries );
271}
Here is the caller graph for this function:

◆ Abc_SortNumCompare()

int Abc_SortNumCompare ( int * pNum1,
int * pNum2 )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 586 of file utilSort.c.

587{
588 return *pNum1 - *pNum2;
589}
Here is the caller graph for this function:

◆ Abc_SortTest()

void Abc_SortTest ( )

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

Synopsis [Testing the sorting procedure.]

Description []

SideEffects []

SeeAlso []

Definition at line 602 of file utilSort.c.

603{
604 int fUseNew = 0;
605 int i, nSize = 50000000;
606 int * pArray = (int *)malloc( sizeof(int) * nSize );
607 int * pPerm;
608 abctime clk;
609 // generate numbers
610 srand( 1000 );
611 for ( i = 0; i < nSize; i++ )
612 pArray[i] = rand();
613
614 // try sorting
615 if ( fUseNew )
616 {
617 int fUseCost = 1;
618 if ( fUseCost )
619 {
620 clk = Abc_Clock();
621 pPerm = Abc_MergeSortCost( pArray, nSize );
622 Abc_PrintTime( 1, "New sort", Abc_Clock() - clk );
623 // check
624 for ( i = 1; i < nSize; i++ )
625 assert( pArray[pPerm[i-1]] <= pArray[pPerm[i]] );
626 free( pPerm );
627 }
628 else
629 {
630 clk = Abc_Clock();
631 Abc_MergeSort( pArray, nSize );
632 Abc_PrintTime( 1, "New sort", Abc_Clock() - clk );
633 // check
634 for ( i = 1; i < nSize; i++ )
635 assert( pArray[i-1] <= pArray[i] );
636 }
637 }
638 else
639 {
640 clk = Abc_Clock();
641 qsort( (void *)pArray, (size_t)nSize, sizeof(int), (int (*)(const void *, const void *)) Abc_SortNumCompare );
642 Abc_PrintTime( 1, "Old sort", Abc_Clock() - clk );
643 // check
644 for ( i = 1; i < nSize; i++ )
645 assert( pArray[i-1] <= pArray[i] );
646 }
647
648 free( pArray );
649}
void Abc_MergeSort(int *pInput, int nSize)
Definition utilSort.c:129
int * Abc_MergeSortCost(int *pCosts, int nSize)
Definition utilSort.c:442
int Abc_SortNumCompare(int *pNum1, int *pNum2)
Definition utilSort.c:586
Here is the call graph for this function: