summaryrefslogtreecommitdiffstats
path: root/src/sat/xsat/xsatUtils.h
blob: 7f774d85b562bff64d74535e64caa2619dc73e77 (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
/**CFile****************************************************************

  FileName    [xsatUtils.h]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [xSAT - A SAT solver written in C.
               Read the license file for more info.]

  Synopsis    [Utility functions used in xSAT]

  Author      [Bruno Schmitt <boschmitt@inf.ufrgs.br>]

  Affiliation [UC Berkeley / UFRGS]

  Date        [Ver. 1.0. Started - November 10, 2016.]

  Revision    []

***********************************************************************/
#ifndef ABC__sat__xSAT__xsatUtils_h
#define ABC__sat__xSAT__xsatUtils_h

////////////////////////////////////////////////////////////////////////
///                          INCLUDES                                ///
////////////////////////////////////////////////////////////////////////
#include "misc/util/abc_global.h"

ABC_NAMESPACE_HEADER_START

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void xSAT_UtilSelectSort( void** pArray, int nSize, int(* CompFnct )( const void *, const void * ) )
{
    int i, j, iBest;
    void* pTmp;

    for ( i = 0; i < ( nSize - 1 ); i++ )
    {
        iBest = i;
        for ( j = i + 1; j < nSize; j++ )
        {
            if ( CompFnct( pArray[j], pArray[iBest] ) )
                iBest = j;
        }
        pTmp = pArray[i];
        pArray[i] = pArray[iBest];
        pArray[iBest] = pTmp;
    }
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static void xSAT_UtilSort( void** pArray, int nSize, int(* CompFnct )( const void *, const void *) )
{
    if ( nSize <= 15 )
        xSAT_UtilSelectSort( pArray, nSize, CompFnct );
    else
    {
        void* pPivot = pArray[nSize / 2];
        void* pTmp;
        int i = -1;
        int j = nSize;

        for(;;)
        {
            do i++; while( CompFnct( pArray[i], pPivot ) );
            do j--; while( CompFnct( pPivot, pArray[j] ) );

            if ( i >= j )
                break;

            pTmp = pArray[i];
            pArray[i] = pArray[j];
            pArray[j] = pTmp;
        }

        xSAT_UtilSort( pArray, i, CompFnct );
        xSAT_UtilSort( pArray + i, ( nSize - i ), CompFnct );
    }
}

ABC_NAMESPACE_HEADER_END

#endif
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////