1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_MC_ODPOR_WAKEUP_TREE_HPP
7 #define SIMGRID_MC_ODPOR_WAKEUP_TREE_HPP
9 #include "src/mc/explo/odpor/WakeupTreeIterator.hpp"
10 #include "src/mc/explo/odpor/odpor_forward.hpp"
13 #include <unordered_map>
15 namespace simgrid::mc::odpor {
17 class WakeupTreeNode {
19 explicit WakeupTreeNode(const PartialExecution& u) : seq_(u) {}
20 explicit WakeupTreeNode(PartialExecution&& u) : seq_(std::move(u)) {}
22 /** An ordered list of children of for this node in the tree */
23 std::list<WakeupTreeNode*> children_;
25 /** @brief The contents of the node */
26 PartialExecution seq_;
28 /** Allows the owning tree to insert directly into the child */
32 const auto begin() const { return this->children_.begin(); }
33 const auto end() const { return this->children_.end(); }
34 const auto rbegin() const { return this->children_.rbegin(); }
35 const auto rend() const { return this->children_.rend(); }
37 const PartialExecution& get_sequence() const { return seq_; }
38 const std::list<WakeupTreeNode*>& get_ordered_children() const { return children_; }
40 bool is_leaf() const { return children_.empty(); }
42 /** Insert a node `node` as a new child of this node */
43 void add_child(WakeupTreeNode* node) { this->children_.push_back(node); }
48 /** @brief The root node of the tree */
49 const WakeupTreeNode* const root;
52 * @brief All of the nodes that are currently are a part of the tree
54 * @invariant Each node event maps itself to the owner of that node,
55 * i.e. the unique pointer that manages the data at the address. The tree owns all
56 * of the addresses that are referenced by the nodes WakeupTreeNode and Configuration.
57 * ODPOR guarantees that nodes are persisted as long as needed.
59 std::unordered_map<WakeupTreeNode*, std::unique_ptr<WakeupTreeNode>> nodes_;
62 * @brief Creates a new, disconnected node in this tree
64 WakeupTreeNode* make_node(const PartialExecution& u);
66 /* Allow the iterator to access the contents of the tree */
67 friend WakeupTreeIterator;
71 ~WakeupTree() = default;
73 auto begin() const { return WakeupTreeIterator(*this); }
74 auto end() const { return WakeupTreeIterator(); }
77 * @brief Inserts an sequence `seq` of processes into the tree
78 * such that that this tree is a wakeup tree relative to the
81 void insert(const Execution&, const PartialExecution& seq);
84 } // namespace simgrid::mc::odpor