Move CTNode class to sourcef file

This commit is contained in:
Tiago Gomes 2013-03-09 19:41:17 +00:00
parent 2da7249247
commit 21c401c0dd
2 changed files with 88 additions and 75 deletions

View File

@ -1,6 +1,7 @@
#include <queue>
#include <iostream>
#include <ostream>
#include <fstream>
#include "ConstraintTree.h"
@ -9,6 +10,79 @@
namespace Horus {
class CTNode {
public:
CTNode (const CTNode& n, const CTChilds& chs = CTChilds())
: symbol_(n.symbol()), childs_(chs), level_(n.level()) { }
CTNode (Symbol s, unsigned l, const CTChilds& chs = CTChilds())
: symbol_(s), childs_(chs), level_(l) { }
unsigned level() const { return level_; }
void setLevel (unsigned level) { level_ = level; }
Symbol symbol() const { return symbol_; }
void setSymbol (Symbol s) { symbol_ = s; }
CTChilds& childs() { return childs_; }
const CTChilds& childs() const { return childs_; }
size_t nrChilds() const { return childs_.size(); }
bool isRoot() const { return level_ == 0; }
bool isLeaf() const { return childs_.empty(); }
CTChilds::iterator findSymbol (Symbol symb);
void mergeSubtree (CTNode*, bool = true);
void removeChild (CTNode*);
void removeChilds();
void removeAndDeleteChild (CTNode*);
void removeAndDeleteAllChilds();
SymbolSet childSymbols() const;
static CTNode* copySubtree (const CTNode*);
static void deleteSubtree (CTNode*);
private:
void updateChildLevels (CTNode*, unsigned);
Symbol symbol_;
CTChilds childs_;
unsigned level_;
DISALLOW_ASSIGN (CTNode);
};
inline CTChilds::iterator
CTNode::findSymbol (Symbol symb)
{
CTNode tmp (symb, 0);
return childs_.find (&tmp);
}
inline bool
CmpSymbol::operator() (const CTNode* n1, const CTNode* n2) const
{
return n1->symbol() < n2->symbol();
}
void
CTNode::mergeSubtree (CTNode* n, bool updateLevels)
{
@ -224,10 +298,11 @@ ConstraintTree::ConstraintTree (const ConstraintTree& ct)
ConstraintTree::ConstraintTree (
const CTChilds& rootChilds,
const LogVars& logVars)
: root_(new CTNode (0, 0, rootChilds)),
: root_(new CTNode (Symbol (0), unsigned (0), rootChilds)),
logVars_(logVars),
logVarSet_(logVars)
{
}
@ -239,6 +314,14 @@ ConstraintTree::~ConstraintTree()
bool
ConstraintTree::empty() const
{
return root_->childs().empty();
}
void
ConstraintTree::addTuple (const Tuple& tuple)
{

View File

@ -6,7 +6,6 @@
#include <vector>
#include <algorithm>
#include <string>
#include <ostream>
#include "TinySet.h"
#include "LiftedUtils.h"
@ -22,81 +21,12 @@ typedef std::vector<CTNode*> CTNodes;
typedef std::vector<ConstraintTree*> ConstraintTrees;
class CTNode {
private:
struct CmpSymbol {
bool operator() (const CTNode* n1, const CTNode* n2) const {
return n1->symbol() < n2->symbol();
}};
public:
typedef TinySet<CTNode*, CmpSymbol> CTChilds;
CTNode (const CTNode& n, const CTChilds& chs = CTChilds())
: symbol_(n.symbol()), childs_(chs), level_(n.level()) { }
CTNode (Symbol s, unsigned l, const CTChilds& chs = CTChilds())
: symbol_(s), childs_(chs), level_(l) { }
unsigned level() const { return level_; }
void setLevel (unsigned level) { level_ = level; }
Symbol symbol() const { return symbol_; }
void setSymbol (Symbol s) { symbol_ = s; }
CTChilds& childs() { return childs_; }
const CTChilds& childs() const { return childs_; }
size_t nrChilds() const { return childs_.size(); }
bool isRoot() const { return level_ == 0; }
bool isLeaf() const { return childs_.empty(); }
CTChilds::iterator findSymbol (Symbol symb);
void mergeSubtree (CTNode*, bool = true);
void removeChild (CTNode*);
void removeChilds();
void removeAndDeleteChild (CTNode*);
void removeAndDeleteAllChilds();
SymbolSet childSymbols() const;
static CTNode* copySubtree (const CTNode*);
static void deleteSubtree (CTNode*);
private:
void updateChildLevels (CTNode*, unsigned);
Symbol symbol_;
CTChilds childs_;
unsigned level_;
DISALLOW_ASSIGN (CTNode);
struct CmpSymbol {
bool operator() (const CTNode* n1, const CTNode* n2) const;
};
typedef CTNode::CTChilds CTChilds;
inline CTChilds::iterator
CTNode::findSymbol (Symbol symb)
{
CTNode tmp (symb, 0);
return childs_.find (&tmp);
}
std::ostream& operator<< (std::ostream&, const CTNode&);
typedef TinySet<CTNode*, CmpSymbol> CTChilds;
class ConstraintTree {
@ -117,7 +47,7 @@ class ConstraintTree {
CTNode* root() const { return root_; }
bool empty() const { return root_->childs().empty(); }
bool empty() const;
const LogVars& logVars() const;