7 #ifndef GRAPHGEN_DRAG_H_
8 #define GRAPHGEN_DRAG_H_
14 #include <unordered_map>
15 #include <unordered_set>
43 return left ==
nullptr &&
right ==
nullptr;
49 std::vector<std::unique_ptr<node>>
nodes_;
52 template<
typename... Args>
54 nodes_.emplace_back(std::make_unique<node>(std::forward<Args>(args)...));
55 return nodes_.back().get();
95 return copies[n] = nn;
105 std::unordered_map<node*, node*> copies;
106 for (
const auto& x : bd.
roots_) {
119 std::unordered_map<node*, node*> copies;
120 for (
const auto& x : bd.
roots_) {
129 for (
auto& n : tracked_nodes) {
A BinaryDrag is the GRAPHGEN implementation of a Binary Directed Rooted Acyclic Graph (DRAG in short)
friend void swap(BinaryDrag &bd1, BinaryDrag &bd2)
node * MakeCopyRecursive(node *n, std::unordered_map< node *, node * > &copies)
Recursive function to copy a BinaryDrag.
BinaryDrag(BinaryDrag &&t)
node * make_root()
Creates a new root updating the roots_ vector.
node * GetRoot() const
Returns the last root of the BinaryDrag.
BinaryDrag & operator=(BinaryDrag t)
Copy assignment.
BinaryDrag(const BinaryDrag &bd, std::vector< node * > &tracked_nodes)
Special copy constructor that allows to track where the nodes in a tree have been copied to.
BinaryDrag()
Empty constructor.
BinaryDrag(const BinaryDrag &bd)
Copy constructor.
void AddRoot(node *r)
Adds a new root to the vector of roots.
std::vector< node * > roots_
node * make_node(Args &&... args)
Creates and returns a new node updating the nodes_ vector.
std::vector< std::unique_ptr< node > > nodes_
Vector of unique pointers to BinaryDrag nodes. This is useful to automatically free the memory of the...
Defines a node of the BinaryDrag.
node(T d, node *l, node *r)