Move CTNode class to sourcef file
This commit is contained in:
parent
2da7249247
commit
21c401c0dd
@ -1,6 +1,7 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "ConstraintTree.h"
|
#include "ConstraintTree.h"
|
||||||
@ -9,6 +10,79 @@
|
|||||||
|
|
||||||
namespace Horus {
|
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
|
void
|
||||||
CTNode::mergeSubtree (CTNode* n, bool updateLevels)
|
CTNode::mergeSubtree (CTNode* n, bool updateLevels)
|
||||||
{
|
{
|
||||||
@ -224,10 +298,11 @@ ConstraintTree::ConstraintTree (const ConstraintTree& ct)
|
|||||||
ConstraintTree::ConstraintTree (
|
ConstraintTree::ConstraintTree (
|
||||||
const CTChilds& rootChilds,
|
const CTChilds& rootChilds,
|
||||||
const LogVars& logVars)
|
const LogVars& logVars)
|
||||||
: root_(new CTNode (0, 0, rootChilds)),
|
: root_(new CTNode (Symbol (0), unsigned (0), rootChilds)),
|
||||||
logVars_(logVars),
|
logVars_(logVars),
|
||||||
logVarSet_(logVars)
|
logVarSet_(logVars)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -239,6 +314,14 @@ ConstraintTree::~ConstraintTree()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ConstraintTree::empty() const
|
||||||
|
{
|
||||||
|
return root_->childs().empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ConstraintTree::addTuple (const Tuple& tuple)
|
ConstraintTree::addTuple (const Tuple& tuple)
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ostream>
|
|
||||||
|
|
||||||
#include "TinySet.h"
|
#include "TinySet.h"
|
||||||
#include "LiftedUtils.h"
|
#include "LiftedUtils.h"
|
||||||
@ -22,81 +21,12 @@ typedef std::vector<CTNode*> CTNodes;
|
|||||||
typedef std::vector<ConstraintTree*> ConstraintTrees;
|
typedef std::vector<ConstraintTree*> ConstraintTrees;
|
||||||
|
|
||||||
|
|
||||||
class CTNode {
|
struct CmpSymbol {
|
||||||
private:
|
bool operator() (const CTNode* n1, const CTNode* n2) const;
|
||||||
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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef CTNode::CTChilds CTChilds;
|
typedef TinySet<CTNode*, CmpSymbol> CTChilds;
|
||||||
|
|
||||||
|
|
||||||
inline CTChilds::iterator
|
|
||||||
CTNode::findSymbol (Symbol symb)
|
|
||||||
{
|
|
||||||
CTNode tmp (symb, 0);
|
|
||||||
return childs_.find (&tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::ostream& operator<< (std::ostream&, const CTNode&);
|
|
||||||
|
|
||||||
|
|
||||||
class ConstraintTree {
|
class ConstraintTree {
|
||||||
@ -117,7 +47,7 @@ class ConstraintTree {
|
|||||||
|
|
||||||
CTNode* root() const { return root_; }
|
CTNode* root() const { return root_; }
|
||||||
|
|
||||||
bool empty() const { return root_->childs().empty(); }
|
bool empty() const;
|
||||||
|
|
||||||
const LogVars& logVars() const;
|
const LogVars& logVars() const;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user