#ifndef __SATClause__
#define __SATClause__
#include <iosfwd>
#include "Forwards.hpp"
#include "Lib/Metaiterators.hpp"
#include "Lib/Reflection.hpp"
#include "SATLiteral.hpp"
namespace SAT {
using namespace Lib;
using namespace Kernel;
class SATClause
{
public:
DECL_ELEMENT_TYPE(SATLiteral);
auto iter() const { return arrayIter(*this); }
SATClause(unsigned length);
SATInference* inference() const { return _inference; }
void setInference(SATInference* val);
void* operator new(size_t,unsigned length);
void operator delete(void *, size_t);
unsigned defaultHash() const {
unsigned hash = 0;
for(unsigned i = 0; i < length(); i++)
hash ^= DefaultHash::hash(_literals[i]);
return hash;
}
bool operator==(const SATClause &other) const {
if(length() != other.length())
return false;
for(unsigned i = 0; i < length(); i++)
if(_literals[i] != other[i])
return false;
return true;
}
bool operator!=(const SATClause &other) const { return !operator==(other); }
SATLiteral& operator[] (int n)
{ return _literals[n]; }
const SATLiteral& operator[] (int n) const
{ return const_cast<const SATLiteral&>(_literals[n]); }
unsigned length() const { return _length; }
unsigned size() const { return _length; }
SATLiteral* literals() { return _literals; }
bool isEmpty() const { return _length == 0; }
void sort();
void destroy();
static SATClause* removeDuplicateLiterals(SATClause *cl);
static SATClause* fromStack(SATLiteralStack& stack);
unsigned number = 0;
private:
unsigned _length : 31;
unsigned _nonDestroyable : 1;
SATInference* _inference;
SATLiteral _literals[1];
static unsigned _lastNumber;
};
std::ostream &operator<<(std::ostream &out, const SATClause &cl);
};
#endif