Mungojerrie  1.1
Mungojerrie
Stree.hh
Go to the documentation of this file.
1 #ifndef STREE_H_
2 #define STREE_H_
3 
46 #include <vector>
47 #include <set>
48 #include <string>
49 #include <sstream>
50 #include "State.hh"
51 
59 class Stree {
60 public:
62  Stree(void);
64  int size(void) const { return numNodes; }
66  std::set<State> getLabel(int node) const {return label[node]; }
68  void setLabel(int node, std::set<State> newlabel) { label[node] = newlabel; }
70  void addLastChild(int parent, std::set<State> const & childLabel);
72  void removeSubtree(int node);
74  void makeContiguous(void);
76  void restrictLabels(void);
78  bool isGreen(int node) const;
80  void removeDescendants(int node);
82  void preorder(std::vector<int> &order) const;
84  bool isIsomorphic(Stree const &other, int root = 0, int otherRoot = 0) const;
86  std::string toString(void) const;
88  std::string toDot(std::string graphname = std::string("tree"),
89  std::string subgraph = std::string("")) const;
91  static int constexpr undef = -1;
92 private:
93  bool isDefined(int node) const { return node != undef; }
94  void restrictLabelsRecur(int node, std::set<State> & subset);
95  void preorderRecur(std::vector<int> &order, int node = 0) const;
96  void toStringRecur(int node, std::ostringstream & oss) const;
97  size_t numNodes;
98  std::vector< std::set<State> > label;
99  std::vector<int> parent;
100  std::vector<int> elder;
101  std::vector<int> younger;
102  std::vector<int> lastChild;
103 };
104 
106 std::ostream & operator<<(std::ostream & os, Stree const & t);
107 
108 #endif
Stree::setLabel
void setLabel(int node, std::set< State > newlabel)
Sets the label of a node in the tree.
Definition: Stree.hh:68
operator<<
std::ostream & operator<<(std::ostream &os, Stree const &t)
Stream insertion operator for Safra trees.
Stree::undef
static constexpr int undef
Index of an undefined node.
Definition: Stree.hh:91
State.hh
Basic type definitions.
Stree::size
int size(void) const
Returns the number of nodes in the tree.
Definition: Stree.hh:64
Stree::Stree
Stree(void)
Constructor.
Definition: Stree.cc:54
Stree
Class of compact Safra trees used for Piterman's NBW to DPW procedure.
Definition: Stree.hh:59
Stree::removeSubtree
void removeSubtree(int node)
Removes the subtree rooted at "node.".
Definition: Stree.cc:81
Stree::removeDescendants
void removeDescendants(int node)
Removes the descendants of a node from the tree.
Definition: Stree.cc:212
Stree::isGreen
bool isGreen(int node) const
Checks whether node of tree "flashes green.".
Definition: Stree.cc:196
Stree::makeContiguous
void makeContiguous(void)
Gives contiguous numbers to the nodes of the tree.
Definition: Stree.cc:112
Stree::addLastChild
void addLastChild(int parent, std::set< State > const &childLabel)
Adds a node to the tree as last child of "parent.".
Definition: Stree.cc:57
Stree::isIsomorphic
bool isIsomorphic(Stree const &other, int root=0, int otherRoot=0) const
Compares two trees.
Definition: Stree.cc:247
Stree::restrictLabels
void restrictLabels(void)
Restricts the label of a node to help restore the tree invariant.
Definition: Stree.cc:159
Stree::toDot
std::string toDot(std::string graphname=std::string("tree"), std::string subgraph=std::string("")) const
Converts the tree to dot format.
Definition: Stree.cc:313
Stree::preorder
void preorder(std::vector< int > &order) const
Returns the nodes of the tree in preorder.
Definition: Stree.cc:222
Stree::toString
std::string toString(void) const
Returns a string describing the tree.
Definition: Stree.cc:274
Stree::getLabel
std::set< State > getLabel(int node) const
Returns the set of states that label a node of the tree.
Definition: Stree.hh:66