Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add skeleton of implementation for tree insertion
[simgrid.git] / src / mc / explo / odpor / WakeupTree.hpp
1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_MC_ODPOR_WAKEUP_TREE_HPP
7 #define SIMGRID_MC_ODPOR_WAKEUP_TREE_HPP
8
9 #include "src/mc/explo/odpor/WakeupTreeIterator.hpp"
10 #include "src/mc/explo/odpor/odpor_forward.hpp"
11
12 #include <memory>
13 #include <unordered_map>
14
15 namespace simgrid::mc::odpor {
16
17 class WakeupTreeNode {
18 private:
19   explicit WakeupTreeNode(const ProcessSequence& u) : seq_(u) {}
20
21   /** An ordered list of children of for this node in the tree */
22   std::list<WakeupTreeNode*> children_;
23
24   /** @brief The contents of the node */
25   ProcessSequence seq_;
26
27   /** Allows the owning tree to insert directly into the child */
28   friend WakeupTree;
29
30 public:
31   const auto begin() const { return this->children_.begin(); }
32   const auto end() const { return this->children_.end(); }
33   const auto rbegin() const { return this->children_.rbegin(); }
34   const auto rend() const { return this->children_.rend(); }
35
36   const ProcessSequence& get_sequence() const { return seq_; }
37   const std::list<WakeupTreeNode*>& get_ordered_children() const { return children_; }
38
39   bool is_leaf() const { return children_.empty(); }
40
41   /** Insert a node `node` as a new child of this node */
42   void add_child(WakeupTreeNode* node) { this->children_.push_back(node); }
43 };
44
45 class WakeupTree {
46 private:
47   /** @brief The root node of the tree */
48   const WakeupTreeNode* const root;
49
50   /**
51    * @brief All of the nodes that are currently are a part of the tree
52    *
53    * @invariant Each node event maps itself to the owner of that node,
54    * i.e. the unique pointer that manages the data at the address. The tree owns all
55    * of the addresses that are referenced by the nodes WakeupTreeNode and Configuration.
56    * ODPOR guarantees that nodes are persisted as long as needed.
57    */
58   std::unordered_map<WakeupTreeNode*, std::unique_ptr<WakeupTreeNode>> nodes_;
59
60   /**
61    * @brief Creates a new, disconnected node in this tree
62    */
63   WakeupTreeNode* make_node(const ProcessSequence& u);
64
65   /* Allow the iterator to access the contents of the tree */
66   friend WakeupTreeIterator;
67
68 public:
69   WakeupTree();
70   ~WakeupTree() = default;
71
72   auto begin() const { return WakeupTreeIterator(*this); }
73   auto end() const { return WakeupTreeIterator(); }
74
75   /**
76    * @brief Inserts an sequence `seq` of processes into the tree
77    * such that that this tree is a wakeup tree relative to the
78    * given execution
79    */
80   void insert(const Execution&, const ExecutionSequence& seq);
81 };
82
83 } // namespace simgrid::mc::odpor
84 #endif