Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add WakeupTreeIterator and WakeupTree skeletons
[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/odpor_forward.hpp"
10
11 #include <memory>
12 #include <unordered_map>
13
14 namespace simgrid::mc::odpor {
15
16 class WakeupTreeNode {
17 private:
18   /** An ordered list of children of for this node in the tree */
19   std::list<const WakeupTreeNode*> children_;
20
21   /** @brief The contents of the node */
22   ProcessSequence seq_;
23
24 public:
25   const auto begin() const { return this->children_.begin(); }
26   const auto end() const { return this->children_.end(); }
27   const auto rbegin() const { return this->children_.rbegin(); }
28   const auto rend() const { return this->children_.rend(); }
29
30   const ProcessSequence& get_sequence() const { return seq_; }
31   const std::list<const WakeupTreeNode*>& get_ordered_children() const { return children_; }
32
33   bool is_leaf() const { return children_.empty(); }
34 };
35
36 class WakeupTree {
37 private:
38   /** @brief The root node of the tree */
39   const WakeupTreeNode* const root;
40
41   /**
42    * @brief All of the nodes that are currently are a part of the tree
43    *
44    * @invariant Each node event maps itself to the owner of that node,
45    * i.e. the unique pointer that manages the data at the address. The tree owns all
46    * of the addresses that are referenced by the nodes WakeupTreeNode and Configuration.
47    * ODPOR guarantees that nodes are persisted as long as needed.
48    */
49   std::unordered_map<const WakeupTreeNode*, std::unique_ptr<WakeupTreeNode>> nodes_;
50
51   /* Allow the iterator to access the contents of the tree */
52   friend WakeupTreeIterator;
53
54 public:
55   WakeupTree();
56
57   /**
58    * @brief Inserts an sequence `seq` of processes into the tree
59    * such that that this tree is a wakeup tree relative to the
60    * given execution
61    */
62   void insert(const Execution&, const ExecutionSequence& seq);
63 };
64
65 } // namespace simgrid::mc::odpor
66 #endif