xsatWatchList.h 6.32 KB
Newer Older
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
/**CFile****************************************************************

  FileName    [xsatWatchList.h]

  SystemName  [ABC: Logic synthesis and verification system.]

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

  Synopsis    [Watch list and its related structures implementation]

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

  Affiliation [UC Berkeley / UFRGS]

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

  Revision    []

***********************************************************************/
#ifndef ABC__sat__xSAT__xsatWatchList_h
#define ABC__sat__xSAT__xsatWatchList_h

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

ABC_NAMESPACE_HEADER_START

////////////////////////////////////////////////////////////////////////
///                    STRUCTURE DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////
typedef struct xSAT_Watcher_t_ xSAT_Watcher_t;
struct xSAT_Watcher_t_
{
37
    unsigned CRef;
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
    int Blocker;
};

typedef struct xSAT_WatchList_t_ xSAT_WatchList_t;
struct xSAT_WatchList_t_
{
    int nCap;
    int nSize;
    xSAT_Watcher_t * pArray;
};

typedef struct xSAT_VecWatchList_t_ xSAT_VecWatchList_t;
struct xSAT_VecWatchList_t_
{
    int nCap;
    int nSize;
    xSAT_WatchList_t * pArray;
};

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void xSAT_WatchListFree( xSAT_WatchList_t * v )
{
    if ( v->pArray )
        ABC_FREE( v->pArray );
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline int  xSAT_WatchListSize( xSAT_WatchList_t * v )
{
    return v->nSize;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void xSAT_WatchListShrink( xSAT_WatchList_t * v, int k )
{
    assert(k <= v->nSize);
    v->nSize = k;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void xSAT_WatchListPush( xSAT_WatchList_t * v, xSAT_Watcher_t e )
{
    assert( v );
121
    if ( v->nSize == v->nCap )
122
    {
123
        int newsize = ( v->nCap < 4 ) ? 4 : ( v->nCap / 2 ) * 3;
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

        v->pArray = ABC_REALLOC( xSAT_Watcher_t, v->pArray, newsize );
        if ( v->pArray == NULL )
        {
            printf( "Failed to realloc memory from %.1f MB to %.1f MB.\n",
                1.0 * v->nCap / (1<<20), 1.0 * newsize / (1<<20) );
            fflush( stdout );
        }
        v->nCap = newsize;
    }

    v->pArray[v->nSize++] = e;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline xSAT_Watcher_t* xSAT_WatchListArray( xSAT_WatchList_t * v )
{
    return v->pArray;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
165
static inline void xSAT_WatchListRemove( xSAT_WatchList_t * v, unsigned CRef )
166 167 168 169
{
    xSAT_Watcher_t* ws = xSAT_WatchListArray(v);
    int j = 0;

170 171 172
    for ( ; ws[j].CRef != CRef; j++ );
    assert( j < xSAT_WatchListSize( v ) );
    memmove( v->pArray + j, v->pArray + j + 1, ( v->nSize - j - 1 ) * sizeof( xSAT_Watcher_t ) );
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
    v->nSize -= 1;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline xSAT_VecWatchList_t * xSAT_VecWatchListAlloc( int nCap )
{
    xSAT_VecWatchList_t * v = ABC_ALLOC( xSAT_VecWatchList_t, 1 );

    v->nCap   = 4;
    v->nSize  = 0;
193
    v->pArray = ( xSAT_WatchList_t * ) ABC_CALLOC(xSAT_WatchList_t, sizeof( xSAT_WatchList_t ) * v->nCap);
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
    return v;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void xSAT_VecWatchListFree( xSAT_VecWatchList_t* v )
{
210 211
    int i;
    for( i = 0; i < v->nSize; i++ )
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
        xSAT_WatchListFree( v->pArray + i );

    ABC_FREE( v->pArray );
    ABC_FREE( v );
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline void xSAT_VecWatchListPush( xSAT_VecWatchList_t* v )
{
    if ( v->nSize == v->nCap )
    {
        int newsize = (v->nCap < 4) ? v->nCap * 2 : (v->nCap / 2) * 3;

        v->pArray = ABC_REALLOC( xSAT_WatchList_t, v->pArray, newsize );
236
        memset( v->pArray + v->nCap, 0, sizeof( xSAT_WatchList_t ) * ( newsize - v->nCap ) );
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
        if ( v->pArray == NULL )
        {
            printf( "Failed to realloc memory from %.1f MB to %.1f MB.\n",
                1.0 * v->nCap / (1<<20), 1.0 * newsize / (1<<20) );
            fflush( stdout );
        }
        v->nCap = newsize;
    }

    v->nSize++;
}

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

  Synopsis    []

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline xSAT_WatchList_t * xSAT_VecWatchListEntry( xSAT_VecWatchList_t* v, int iEntry )
{
    assert( iEntry < v->nCap );
    assert( iEntry < v->nSize );
    return v->pArray + iEntry;
}

ABC_NAMESPACE_HEADER_END

#endif