-
Notifications
You must be signed in to change notification settings - Fork 1
/
ClauseList.h
92 lines (73 loc) · 2.28 KB
/
ClauseList.h
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
#ifndef ClauseList_h
#define ClauseList_h
//////////////////////////////////////////////////////////////////////////////////////////////////
// ClauseList
/////////////////
// OS Includes
#include <assert.h>
//////////////
// Includes
#include "LightweightTypes.h"
/////////////
// Defines
#define INITIAL_SIZE 4
////////////////////////
// Class Declarations
class Clause;
class SATSolver;
class ClauseList {
public:
ClauseList()
: _iClauseCount(0), _iMaxSize(INITIAL_SIZE) { _aClause = new Clause*[_iMaxSize];}
ClauseList(int iInitialSize_)
: _iClauseCount(0), _iMaxSize(iInitialSize_) {_aClause = new Clause*[_iMaxSize];}
~ClauseList() {delete [] _aClause;}
inline void vAddClause(Clause*);
inline void vDeleteClause(Clause*);
void vRemoveDeletedClauses();
void vRemoveRequiredClauses();
void vDestroyDeletedClauses();
inline Clause* pClause(const int iWhich_) const;
int iClauseCount() const {return _iClauseCount;}
void vSortClausesByLength();
// For fast iteration...
Clause** pEntry(const int iWhich_) const { return _aClause + iWhich_; }
Clause** pLastEntry() const { return _aClause + _iClauseCount; }
void vClear() {_iClauseCount = 0;}
void vDestroy();
protected:
void _vExpand();
int _iClauseCount;
Clause** _aClause;
int _iMaxSize;
};
//////////////////////////////////////////////////////////////////////////////////////////////////
// Class Definitions
//////////////////////////////////////////////////////////////////////////////////////////////////
// Inlines
inline Clause* ClauseList::pClause(const int iWhich_) const
{
assert(iWhich_>=0);
assert(iWhich_<_iClauseCount);
return _aClause[iWhich_];
}
inline void ClauseList::vAddClause(Clause* pAddMe_)
{
// We assume there is no need to update iAlmostReady and iNotQuiteReady
// because instantiated counts of the variables will either be zero or ALL
if (_iMaxSize == _iClauseCount) {
_vExpand();
}
_aClause[_iClauseCount++] = pAddMe_;
}
inline void ClauseList::vDeleteClause(Clause* pDeleteMe_)
{
// Assumes the clause is in the list, and probably resides somewhere near the end.
for (Clause** pStart = &_aClause[_iClauseCount-1]; ; pStart--) {
if (*pStart == pDeleteMe_) {
*pStart = _aClause[--_iClauseCount];
return;
}
}
}
#endif // ClauseList_h