diff options
Diffstat (limited to 'tree.h')
-rw-r--r-- | tree.h | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -4,6 +4,7 @@ #include <string> #include <vector> #include <unordered_map> +#include <unordered_set> using namespace std; @@ -13,7 +14,7 @@ int uniqid(); struct Variable{ int id; - Variable(int id):id(id){} + Variable(int id); bool isOperator() const; bool isFixed() const; @@ -25,6 +26,8 @@ struct Variable{ operator int() const; }; +ostream& operator<<(ostream &os,const Variable &v); + namespace std { template <> struct hash<Variable>{ @@ -50,10 +53,11 @@ class Tree{ Node& operator=(const Node &other); Assign* match(const Node &pat,Assign *accum=nullptr) const; - Node* apply(const Assign &as) const; + void collectTemporaries(unordered_set<Variable> &accum) const; int nleaves() const; + int height() const; int compare(const Node &other) const; }; @@ -65,6 +69,8 @@ class Tree{ void replace(Node *subj,const Tree &pat,const Tree &repl,vector<Tree> &accum); + void refreshUnassigned(const Tree &repl,Assign &as) const; + public: Tree(); // Creates invalid tree Tree(const string &expr); @@ -75,8 +81,10 @@ public: bool matches(const Tree &pat) const; vector<Tree> replace(const Tree &pat,const Tree &repl); + unordered_set<Variable> collectTemporaries() const; int nleaves() const; + int height() const; int compare(const Tree &other) const; |