Commit 9d289304 by Alan Mishchenko

Transforming the solver to use different clause representation.

parent 844c385e
...@@ -376,6 +376,7 @@ void Cec_ManSatSolverRecycle( Cec_ManSat_t * p ) ...@@ -376,6 +376,7 @@ void Cec_ManSatSolverRecycle( Cec_ManSat_t * p )
sat_solver_delete( p->pSat ); sat_solver_delete( p->pSat );
} }
p->pSat = sat_solver_new(); p->pSat = sat_solver_new();
p->pSat->factors = ABC_CALLOC( double, 1 );
sat_solver_setnvars( p->pSat, 1000 ); sat_solver_setnvars( p->pSat, 1000 );
// var 0 is not used // var 0 is not used
// var 1 is reserved for const0 node - add the clause // var 1 is reserved for const0 node - add the clause
......
...@@ -2113,6 +2113,7 @@ int Ivy_FraigNodesAreEquiv( Ivy_FraigMan_t * p, Ivy_Obj_t * pOld, Ivy_Obj_t * pN ...@@ -2113,6 +2113,7 @@ int Ivy_FraigNodesAreEquiv( Ivy_FraigMan_t * p, Ivy_Obj_t * pOld, Ivy_Obj_t * pN
if ( p->pSat == NULL ) if ( p->pSat == NULL )
{ {
p->pSat = sat_solver_new(); p->pSat = sat_solver_new();
p->pSat->factors = ABC_CALLOC( double, 1 );
p->nSatVars = 1; p->nSatVars = 1;
sat_solver_setnvars( p->pSat, 1000 ); sat_solver_setnvars( p->pSat, 1000 );
// var 0 is reserved for const1 node - add the clause // var 0 is reserved for const1 node - add the clause
...@@ -2264,6 +2265,7 @@ int Ivy_FraigNodeIsConst( Ivy_FraigMan_t * p, Ivy_Obj_t * pNew ) ...@@ -2264,6 +2265,7 @@ int Ivy_FraigNodeIsConst( Ivy_FraigMan_t * p, Ivy_Obj_t * pNew )
if ( p->pSat == NULL ) if ( p->pSat == NULL )
{ {
p->pSat = sat_solver_new(); p->pSat = sat_solver_new();
p->pSat->factors = ABC_CALLOC( double, 1 );
p->nSatVars = 1; p->nSatVars = 1;
sat_solver_setnvars( p->pSat, 1000 ); sat_solver_setnvars( p->pSat, 1000 );
// var 0 is reserved for const1 node - add the clause // var 0 is reserved for const1 node - add the clause
......
...@@ -596,7 +596,8 @@ Vec_Vec_t * Ssw_ManFindDirectImplications( Aig_Man_t * p, int nFrames, int nConf ...@@ -596,7 +596,8 @@ Vec_Vec_t * Ssw_ManFindDirectImplications( Aig_Man_t * p, int nFrames, int nConf
pReprR = Aig_Regular(pRepr); pReprR = Aig_Regular(pRepr);
if ( pCnf->pVarNums[Aig_ObjId(pReprR)] < 0 ) if ( pCnf->pVarNums[Aig_ObjId(pReprR)] < 0 )
continue; continue;
value = pSat->assigns[ pCnf->pVarNums[Aig_ObjId(pReprR)] ]; // value = pSat->assigns[ pCnf->pVarNums[Aig_ObjId(pReprR)] ];
value = sat_solver_get_var_value( pSat, pCnf->pVarNums[Aig_ObjId(pReprR)] );
if ( value == l_Undef ) if ( value == l_Undef )
continue; continue;
// label this node as taken // label this node as taken
......
...@@ -29,7 +29,7 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA ...@@ -29,7 +29,7 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
#include <assert.h> #include <assert.h>
#include "satVec.h" #include "satVec.h"
#include "satMem.h" #include "vecRec.h"
ABC_NAMESPACE_HEADER_START ABC_NAMESPACE_HEADER_START
...@@ -54,6 +54,8 @@ extern int sat_solver_nclauses(sat_solver* s); ...@@ -54,6 +54,8 @@ extern int sat_solver_nclauses(sat_solver* s);
extern int sat_solver_nconflicts(sat_solver* s); extern int sat_solver_nconflicts(sat_solver* s);
extern void sat_solver_setnvars(sat_solver* s,int n); extern void sat_solver_setnvars(sat_solver* s,int n);
extern int sat_solver_get_var_value(sat_solver* s, int v);
extern void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBegin, lit* assumptionsEnd, int incrementVars ); extern void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBegin, lit* assumptionsEnd, int incrementVars );
extern void Sat_SolverPrintStats( FILE * pFile, sat_solver * p ); extern void Sat_SolverPrintStats( FILE * pFile, sat_solver * p );
...@@ -79,6 +81,9 @@ extern void * sat_solver_store_release( sat_solver * s ); ...@@ -79,6 +81,9 @@ extern void * sat_solver_store_release( sat_solver * s );
struct clause_t; struct clause_t;
typedef struct clause_t clause; typedef struct clause_t clause;
struct varinfo_t;
typedef struct varinfo_t varinfo;
struct sat_solver_t struct sat_solver_t
{ {
int size; // nof variables int size; // nof variables
...@@ -87,8 +92,10 @@ struct sat_solver_t ...@@ -87,8 +92,10 @@ struct sat_solver_t
int qtail; // Tail index of queue. int qtail; // Tail index of queue.
// clauses // clauses
vecp clauses; // List of problem constraints. (contains: clause*) Vec_Rec_t Mem;
vecp learnts; // List of learnt clauses. (contains: clause*) int hLearnts; // the first learnt clause
int hBinary; // the special binary clause
clause * binary;
// activities // activities
#ifdef USE_FLOAT_ACTIVITY #ifdef USE_FLOAT_ACTIVITY
...@@ -100,19 +107,19 @@ struct sat_solver_t ...@@ -100,19 +107,19 @@ struct sat_solver_t
#else #else
int var_inc; // Amount to bump next variable with. int var_inc; // Amount to bump next variable with.
int cla_inc; // Amount to bump next clause with. int cla_inc; // Amount to bump next clause with.
unsigned*activity; // A heuristic measurement of the activity of a variable. unsigned* activity; // A heuristic measurement of the activity of a variable.
#endif #endif
vecp* wlists; // veci* wlists; //
lbool* assigns; // Current values of variables. // varinfo * vi; // variable information
int* orderpos; // Index in variable order.
clause** reasons; //
int* levels; // int* levels; //
lit* trail; char* assigns; // Current values of variables.
char* polarity; char* polarity; //
char* tags; //
clause* binary; // A temporary binary clause int* orderpos; // Index in variable order.
lbool* tags; // int* reasons; //
lit* trail;
veci tagged; // (contains: var) veci tagged; // (contains: var)
veci stack; // (contains: var) veci stack; // (contains: var)
...@@ -141,8 +148,6 @@ struct sat_solver_t ...@@ -141,8 +148,6 @@ struct sat_solver_t
int nCalls; // the number of local restarts int nCalls; // the number of local restarts
int nCalls2; // the number of local restarts int nCalls2; // the number of local restarts
Sat_MmStep_t * pMem;
int fSkipSimplify; // set to one to skip simplification of the clause database int fSkipSimplify; // set to one to skip simplification of the clause database
int fNotUseRandom; // do not allow random decisions with a fixed probability int fNotUseRandom; // do not allow random decisions with a fixed probability
......
...@@ -65,14 +65,6 @@ static inline double drand(double* seed) { ...@@ -65,14 +65,6 @@ static inline double drand(double* seed) {
static inline int irand(double* seed, int size) { static inline int irand(double* seed, int size) {
return (int)(drand(seed) * size); } return (int)(drand(seed) * size); }
static inline int sat_float2int( float Val ) { union { int x; float y; } v; v.y = Val; return v.x; }
static inline float sat_int2float( int Num ) { union { int x; float y; } v; v.x = Num; return v.y; }
//=================================================================================================
// Predeclarations:
static void solver2_sort(void** array, int size, int(*comp)(const void *, const void *));
//================================================================================================= //=================================================================================================
// Variable datatype + minor functions: // Variable datatype + minor functions:
...@@ -82,23 +74,27 @@ static const int varX = 3; ...@@ -82,23 +74,27 @@ static const int varX = 3;
struct varinfo_t struct varinfo_t
{ {
unsigned val : 2; // variable value // unsigned val : 2; // variable value
unsigned pol : 1; // last polarity unsigned pol : 1; // last polarity
unsigned partA : 1; // partA variable unsigned partA : 1; // partA variable
unsigned tag : 4; // conflict analysis tags unsigned tag : 4; // conflict analysis tags
unsigned lev : 24; // variable level // unsigned lev : 24; // variable level
}; };
int var_is_partA (sat_solver2* s, int v) { return s->vi[v].partA; } int var_is_partA (sat_solver2* s, int v) { return s->vi[v].partA; }
void var_set_partA(sat_solver2* s, int v, int partA) { s->vi[v].partA = partA; } void var_set_partA(sat_solver2* s, int v, int partA) { s->vi[v].partA = partA; }
static inline int var_value (sat_solver2* s, int v) { return s->vi[v].val; } //static inline int var_level (sat_solver2* s, int v) { return s->vi[v].lev; }
static inline int var_level (sat_solver2* s, int v) { return s->levels[v]; }
//static inline int var_value (sat_solver2* s, int v) { return s->vi[v].val; }
static inline int var_value (sat_solver2* s, int v) { return s->assigns[v]; }
static inline int var_polar (sat_solver2* s, int v) { return s->vi[v].pol; } static inline int var_polar (sat_solver2* s, int v) { return s->vi[v].pol; }
static inline int var_level (sat_solver2* s, int v) { return s->vi[v].lev; }
static inline void var_set_value (sat_solver2* s, int v, int val) { s->vi[v].val = val; } //static inline void var_set_level (sat_solver2* s, int v, int lev) { s->vi[v].lev = lev; }
static inline void var_set_level (sat_solver2* s, int v, int lev) { s->levels[v] = lev; }
//static inline void var_set_value (sat_solver2* s, int v, int val) { s->vi[v].val = val; }
static inline void var_set_value (sat_solver2* s, int v, int val) { s->assigns[v] = val; }
static inline void var_set_polar (sat_solver2* s, int v, int pol) { s->vi[v].pol = pol; } static inline void var_set_polar (sat_solver2* s, int v, int pol) { s->vi[v].pol = pol; }
static inline void var_set_level (sat_solver2* s, int v, int lev) { s->vi[v].lev = lev; }
// variable tags // variable tags
static inline int var_tag (sat_solver2* s, int v) { return s->vi[v].tag; } static inline int var_tag (sat_solver2* s, int v) { return s->vi[v].tag; }
...@@ -1268,6 +1264,8 @@ void sat_solver2_setnvars(sat_solver2* s,int n) ...@@ -1268,6 +1264,8 @@ void sat_solver2_setnvars(sat_solver2* s,int n)
s->wlists = ABC_REALLOC(veci, s->wlists, s->cap*2); s->wlists = ABC_REALLOC(veci, s->wlists, s->cap*2);
s->vi = ABC_REALLOC(varinfo, s->vi, s->cap); s->vi = ABC_REALLOC(varinfo, s->vi, s->cap);
s->levels = ABC_REALLOC(int, s->levels, s->cap);
s->assigns = ABC_REALLOC(char, s->assigns, s->cap);
s->trail = ABC_REALLOC(lit, s->trail, s->cap); s->trail = ABC_REALLOC(lit, s->trail, s->cap);
s->orderpos = ABC_REALLOC(int, s->orderpos, s->cap); s->orderpos = ABC_REALLOC(int, s->orderpos, s->cap);
s->reasons = ABC_REALLOC(cla, s->reasons, s->cap); s->reasons = ABC_REALLOC(cla, s->reasons, s->cap);
...@@ -1288,7 +1286,9 @@ void sat_solver2_setnvars(sat_solver2* s,int n) ...@@ -1288,7 +1286,9 @@ void sat_solver2_setnvars(sat_solver2* s,int n)
veci_new(&s->wlists[2*var]); veci_new(&s->wlists[2*var]);
if ( s->wlists[2*var+1].ptr == NULL ) if ( s->wlists[2*var+1].ptr == NULL )
veci_new(&s->wlists[2*var+1]); veci_new(&s->wlists[2*var+1]);
*((int*)s->vi + var) = 0; s->vi[var].val = varX; *((int*)s->vi + var) = 0; //s->vi[var].val = varX;
s->levels [var] = 0;
s->assigns [var] = varX;
s->orderpos[var] = veci_size(&s->order); s->orderpos[var] = veci_size(&s->order);
s->reasons [var] = 0; s->reasons [var] = 0;
if ( s->fProofLogging ) if ( s->fProofLogging )
...@@ -1346,6 +1346,8 @@ void sat_solver2_delete(sat_solver2* s) ...@@ -1346,6 +1346,8 @@ void sat_solver2_delete(sat_solver2* s)
veci_delete(&s->wlists[i]); veci_delete(&s->wlists[i]);
ABC_FREE(s->wlists ); ABC_FREE(s->wlists );
ABC_FREE(s->vi ); ABC_FREE(s->vi );
ABC_FREE(s->levels );
ABC_FREE(s->assigns );
ABC_FREE(s->trail ); ABC_FREE(s->trail );
ABC_FREE(s->orderpos ); ABC_FREE(s->orderpos );
ABC_FREE(s->reasons ); ABC_FREE(s->reasons );
......
...@@ -126,6 +126,8 @@ struct sat_solver2_t ...@@ -126,6 +126,8 @@ struct sat_solver2_t
// internal state // internal state
varinfo * vi; // variable information varinfo * vi; // variable information
int* levels; //
char* assigns; //
lit* trail; // sequence of assignment and implications lit* trail; // sequence of assignment and implications
int* orderpos; // Index in variable order. int* orderpos; // Index in variable order.
cla* reasons; // reason clauses cla* reasons; // reason clauses
......
/**************************************************************************************************
MiniSat -- Copyright (c) 2005, Niklas Sorensson
http://www.cs.chalmers.se/Cs/Research/FormalMethods/MiniSat/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**************************************************************************************************/
// Modified to compile with MS Visual Studio 6.0 by Alan Mishchenko
#ifndef satSolver_h
#define satSolver_h
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "satVec.h"
#include "satMem.h"
ABC_NAMESPACE_HEADER_START
//#define USE_FLOAT_ACTIVITY
//=================================================================================================
// Public interface:
struct sat_solver_t;
typedef struct sat_solver_t sat_solver;
extern sat_solver* sat_solver_new(void);
extern void sat_solver_delete(sat_solver* s);
extern int sat_solver_addclause(sat_solver* s, lit* begin, lit* end);
extern int sat_solver_simplify(sat_solver* s);
extern int sat_solver_solve(sat_solver* s, lit* begin, lit* end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal);
extern void sat_solver_rollback( sat_solver* s );
extern int sat_solver_nvars(sat_solver* s);
extern int sat_solver_nclauses(sat_solver* s);
extern int sat_solver_nconflicts(sat_solver* s);
extern void sat_solver_setnvars(sat_solver* s,int n);
extern void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBegin, lit* assumptionsEnd, int incrementVars );
extern void Sat_SolverPrintStats( FILE * pFile, sat_solver * p );
extern int * Sat_SolverGetModel( sat_solver * p, int * pVars, int nVars );
extern void Sat_SolverDoubleClauses( sat_solver * p, int iVar );
// trace recording
extern void Sat_SolverTraceStart( sat_solver * pSat, char * pName );
extern void Sat_SolverTraceStop( sat_solver * pSat );
extern void Sat_SolverTraceWrite( sat_solver * pSat, int * pBeg, int * pEnd, int fRoot );
// clause storage
extern void sat_solver_store_alloc( sat_solver * s );
extern void sat_solver_store_write( sat_solver * s, char * pFileName );
extern void sat_solver_store_free( sat_solver * s );
extern void sat_solver_store_mark_roots( sat_solver * s );
extern void sat_solver_store_mark_clauses_a( sat_solver * s );
extern void * sat_solver_store_release( sat_solver * s );
//=================================================================================================
// Solver representation:
struct clause_t;
typedef struct clause_t clause;
struct sat_solver_t
{
int size; // nof variables
int cap; // size of varmaps
int qhead; // Head index of queue.
int qtail; // Tail index of queue.
// clauses
vecp clauses; // List of problem constraints. (contains: clause*)
vecp learnts; // List of learnt clauses. (contains: clause*)
// activities
#ifdef USE_FLOAT_ACTIVITY
double var_inc; // Amount to bump next variable with.
double var_decay; // INVERSE decay factor for variable activity: stores 1/decay.
float cla_inc; // Amount to bump next clause with.
float cla_decay; // INVERSE decay factor for clause activity: stores 1/decay.
double* activity; // A heuristic measurement of the activity of a variable.
#else
int var_inc; // Amount to bump next variable with.
int cla_inc; // Amount to bump next clause with.
unsigned*activity; // A heuristic measurement of the activity of a variable.
#endif
vecp* wlists; //
lbool* assigns; // Current values of variables.
int* orderpos; // Index in variable order.
clause** reasons; //
int* levels; //
lit* trail;
char* polarity;
clause* binary; // A temporary binary clause
lbool* tags; //
veci tagged; // (contains: var)
veci stack; // (contains: var)
veci order; // Variable order. (heap) (contains: var)
veci trail_lim; // Separator indices for different decision levels in 'trail'. (contains: int)
veci model; // If problem is solved, this vector contains the model (contains: lbool).
veci conf_final; // If problem is unsatisfiable (possibly under assumptions),
// this vector represent the final conflict clause expressed in the assumptions.
int root_level; // Level of first proper decision.
int simpdb_assigns;// Number of top-level assignments at last 'simplifyDB()'.
int simpdb_props; // Number of propagations before next 'simplifyDB()'.
double random_seed;
double progress_estimate;
int verbosity; // Verbosity level. 0=silent, 1=some progress report, 2=everything
stats_t stats;
ABC_INT64_T nConfLimit; // external limit on the number of conflicts
ABC_INT64_T nInsLimit; // external limit on the number of implications
int nRuntimeLimit; // external limit on runtime
veci act_vars; // variables whose activity has changed
double* factors; // the activity factors
int nRestarts; // the number of local restarts
int nCalls; // the number of local restarts
int nCalls2; // the number of local restarts
Sat_MmStep_t * pMem;
int fSkipSimplify; // set to one to skip simplification of the clause database
int fNotUseRandom; // do not allow random decisions with a fixed probability
int * pGlobalVars; // for experiments with global vars during interpolation
// clause store
void * pStore;
int fSolved;
// trace recording
FILE * pFile;
int nClauses;
int nRoots;
veci temp_clause; // temporary storage for a CNF clause
};
static int sat_solver_var_value( sat_solver* s, int v )
{
assert( s->model.ptr != NULL && v < s->size );
return (int)(s->model.ptr[v] == l_True);
}
static int sat_solver_var_literal( sat_solver* s, int v )
{
assert( s->model.ptr != NULL && v < s->size );
return toLitCond( v, s->model.ptr[v] != l_True );
}
static void sat_solver_act_var_clear(sat_solver* s)
{
int i;
for (i = 0; i < s->size; i++)
s->activity[i] = 0.0;
s->var_inc = 1.0;
}
static void sat_solver_compress(sat_solver* s)
{
if ( s->qtail != s->qhead )
{
int RetValue = sat_solver_simplify(s);
assert( RetValue != 0 );
}
}
static int sat_solver_final(sat_solver* s, int ** ppArray)
{
*ppArray = s->conf_final.ptr;
return s->conf_final.size;
}
static int sat_solver_set_runtime_limit(sat_solver* s, int Limit)
{
int nRuntimeLimit = s->nRuntimeLimit;
s->nRuntimeLimit = Limit;
return nRuntimeLimit;
}
static int sat_solver_set_random(sat_solver* s, int fNotUseRandom)
{
int fNotUseRandomOld = s->fNotUseRandom;
s->fNotUseRandom = fNotUseRandom;
return fNotUseRandomOld;
}
ABC_NAMESPACE_HEADER_END
#endif
...@@ -58,6 +58,7 @@ static void Sat_SolverClauseWriteDimacs( FILE * pFile, clause * pC, int fIncreme ...@@ -58,6 +58,7 @@ static void Sat_SolverClauseWriteDimacs( FILE * pFile, clause * pC, int fIncreme
***********************************************************************/ ***********************************************************************/
void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBegin, lit* assumptionsEnd, int incrementVars ) void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBegin, lit* assumptionsEnd, int incrementVars )
{ {
/*
FILE * pFile; FILE * pFile;
void ** pClauses; void ** pClauses;
int nClauses, i; int nClauses, i;
...@@ -110,6 +111,7 @@ void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBe ...@@ -110,6 +111,7 @@ void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBe
fprintf( pFile, "\n" ); fprintf( pFile, "\n" );
fclose( pFile ); fclose( pFile );
*/
} }
/**Function************************************************************* /**Function*************************************************************
...@@ -273,6 +275,7 @@ int * Sat_Solver2GetModel( sat_solver2 * p, int * pVars, int nVars ) ...@@ -273,6 +275,7 @@ int * Sat_Solver2GetModel( sat_solver2 * p, int * pVars, int nVars )
***********************************************************************/ ***********************************************************************/
void Sat_SolverDoubleClauses( sat_solver * p, int iVar ) void Sat_SolverDoubleClauses( sat_solver * p, int iVar )
{ {
/*
clause * pClause; clause * pClause;
lit Lit, * pLits; lit Lit, * pLits;
int RetValue, nClauses, nVarsOld, nLitsOld, nLits, c, v; int RetValue, nClauses, nVarsOld, nLitsOld, nLits, c, v;
...@@ -305,6 +308,7 @@ void Sat_SolverDoubleClauses( sat_solver * p, int iVar ) ...@@ -305,6 +308,7 @@ void Sat_SolverDoubleClauses( sat_solver * p, int iVar )
for ( v = 0; v < nLits; v++ ) for ( v = 0; v < nLits; v++ )
pLits[v] -= nLitsOld; pLits[v] -= nLitsOld;
} }
*/
} }
......
...@@ -66,6 +66,9 @@ struct Vec_Rec_t_ ...@@ -66,6 +66,9 @@ struct Vec_Rec_t_
for ( c = 1; c <= p->nChunks; c++ ) \ for ( c = 1; c <= p->nChunks; c++ ) \
for ( s = 0; p->pChunks[c][s] && ((Handle) = (((c)<<16)|(s))); s += Size, assert(s < p->Mask) ) for ( s = 0; p->pChunks[c][s] && ((Handle) = (((c)<<16)|(s))); s += Size, assert(s < p->Mask) )
#define Vec_RecForEachEntryStart( p, Size, Handle, c, s, hStart ) \
for ( c = Vec_RecChunk(hStart), s = Vec_RecShift(hStart); c <= p->nChunks; c++, s = 0 ) \
for ( ; p->pChunks[c][s] && ((Handle) = (((c)<<16)|(s))); s += Size, assert(s < p->Mask) )
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS /// /// FUNCTION DEFINITIONS ///
...@@ -97,6 +100,22 @@ static inline Vec_Rec_t * Vec_RecAlloc() ...@@ -97,6 +100,22 @@ static inline Vec_Rec_t * Vec_RecAlloc()
p->pChunks[1][0] = 0; p->pChunks[1][0] = 0;
return p; return p;
} }
static inline void Vec_RecAlloc_( Vec_Rec_t * p )
{
// Vec_Rec_t * p;
// p = ABC_CALLOC( Vec_Rec_t, 1 );
memset( p, 0, sizeof(Vec_Rec_t) );
p->LogSize = 15; // chunk size = 2^15 ints = 128 Kb
p->Mask = (1 << p->LogSize) - 1;
p->hCurrent = (1 << 16);
p->nChunks = 1;
p->nChunksAlloc = 16;
p->pChunks = ABC_CALLOC( int *, p->nChunksAlloc );
p->pChunks[0] = NULL;
p->pChunks[1] = ABC_ALLOC( int, (1 << 16) );
p->pChunks[1][0] = 0;
// return p;
}
/**Function************************************************************* /**Function*************************************************************
...@@ -239,6 +258,14 @@ static inline void Vec_RecFree( Vec_Rec_t * p ) ...@@ -239,6 +258,14 @@ static inline void Vec_RecFree( Vec_Rec_t * p )
ABC_FREE( p->pChunks ); ABC_FREE( p->pChunks );
ABC_FREE( p ); ABC_FREE( p );
} }
static inline void Vec_RecFree_( Vec_Rec_t * p )
{
int i;
for ( i = 0; i < p->nChunksAlloc; i++ )
ABC_FREE( p->pChunks[i] );
ABC_FREE( p->pChunks );
// ABC_FREE( p );
}
/**Function************************************************************* /**Function*************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment