Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove nested code blocks (Sonar).
[simgrid.git] / src / mc / explo / odpor / WakeupTree.cpp
index 7b73e6c2b24bf6a118385dc100a9ceb5904fb928..8898b66bb61d6e5bb0a680ca53b7362600e03da1 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <algorithm>
 #include <exception>
+#include <memory>
 #include <queue>
 
 namespace simgrid::mc::odpor {
@@ -26,7 +27,7 @@ PartialExecution WakeupTreeNode::get_sequence() const
   // and instead track this with the iterator
   PartialExecution seq_;
   const WakeupTreeNode* cur_node = this;
-  while (cur_node != nullptr and !cur_node->is_root()) {
+  while (cur_node != nullptr && not cur_node->is_root()) {
     seq_.push_front(cur_node->action_);
     cur_node = cur_node->parent_;
   }
@@ -46,7 +47,7 @@ void WakeupTreeNode::detatch_from_parent()
   }
 }
 
-WakeupTree::WakeupTree() : WakeupTree(std::unique_ptr<WakeupTreeNode>(new WakeupTreeNode({}))) {}
+WakeupTree::WakeupTree() : WakeupTree(std::make_unique<WakeupTreeNode>()) {}
 WakeupTree::WakeupTree(std::unique_ptr<WakeupTreeNode> root) : root_(root.get())
 {
   this->insert_node(std::move(root));
@@ -120,7 +121,7 @@ void WakeupTree::remove_subtree_rooted_at(WakeupTreeNode* root)
   std::list<WakeupTreeNode*> subtree_contents{root};
   std::list<WakeupTreeNode*> frontier{root};
   while (not frontier.empty()) {
-    auto node = frontier.front();
+    const auto* node = frontier.front();
     frontier.pop_front();
     for (const auto& child : node->get_ordered_children()) {
       frontier.push_back(child);
@@ -145,7 +146,7 @@ void WakeupTree::remove_min_single_process_subtree()
   }
 }
 
-bool WakeupTree::contains(WakeupTreeNode* node) const
+bool WakeupTree::contains(const WakeupTreeNode* node) const
 {
   return std::find_if(this->nodes_.begin(), this->nodes_.end(), [=](const auto& pair) { return pair.first == node; }) !=
          this->nodes_.end();
@@ -153,7 +154,7 @@ bool WakeupTree::contains(WakeupTreeNode* node) const
 
 WakeupTreeNode* WakeupTree::make_node(std::shared_ptr<Transition> u)
 {
-  auto node                 = std::unique_ptr<WakeupTreeNode>(new WakeupTreeNode(std::move(u)));
+  auto node                 = std::make_unique<WakeupTreeNode>(std::move(u));
   auto* node_handle         = node.get();
   this->nodes_[node_handle] = std::move(node);
   return node_handle;
@@ -181,7 +182,7 @@ WakeupTree::InsertionResult WakeupTree::insert(const Execution& E, const Partial
         shortest_sequence.has_value()) {
       // Insert the sequence as a child of `node`, but only
       // if the node is not already a leaf
-      if (not node->is_leaf() or node == this->root_) {
+      if (not node->is_leaf() || node == this->root_) {
         // NOTE: It's entirely possible that the shortest
         // sequence we are inserting is empty. Consider the
         // following two cases:
@@ -216,4 +217,4 @@ void WakeupTree::insert_sequence_after(WakeupTreeNode* node, const PartialExecut
   }
 }
 
-} // namespace simgrid::mc::odpor
\ No newline at end of file
+} // namespace simgrid::mc::odpor