X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a9a21312483780dd659eba21102f79f207984f7c..c6683b41cf9ecda70c1d4d75d1effc61903a894f:/src/mc/explo/odpor/WakeupTreeIterator.cpp diff --git a/src/mc/explo/odpor/WakeupTreeIterator.cpp b/src/mc/explo/odpor/WakeupTreeIterator.cpp index bb479f37cf..6c81203193 100644 --- a/src/mc/explo/odpor/WakeupTreeIterator.cpp +++ b/src/mc/explo/odpor/WakeupTreeIterator.cpp @@ -8,9 +8,9 @@ namespace simgrid::mc::odpor { -WakeupTreeIterator::WakeupTreeIterator(const WakeupTree& tree) +WakeupTreeIterator::WakeupTreeIterator(const WakeupTree& tree) : root_list{tree.root_} { - // post_order_iteration.push(tree.root); + post_order_iteration.push(root_list.begin()); push_until_left_most_found(); } @@ -21,11 +21,19 @@ void WakeupTreeIterator::push_until_left_most_found() // one node in the tree won't have any children, // so the loop will eventually terminate auto* cur_top_node = *post_order_iteration.top(); - while (!cur_top_node->is_leaf()) { + while (not cur_top_node->is_leaf()) { // INVARIANT: Since we push children in // reverse order (right-most to left-most), // we ensure that we'll always process left-most // children first + auto& children = cur_top_node->children_; + + for (auto iter = children.rbegin(); iter != children.rend(); ++iter) { + // iter.base() points one element past where we seek; hence, + // we move it over one position + post_order_iteration.push(std::prev(iter.base())); + } + cur_top_node = *post_order_iteration.top(); } } @@ -52,12 +60,11 @@ void WakeupTreeIterator::increment() // Otherwise, look at the next top node. If // `prev_top` is that node's right-most child, // then we don't attempt to re-add `next_top`'s - // children again for we would have already seen them - const auto* next_top_node = *post_order_iteration.top(); - + // children again for we would have already seen them. // To actually determine "right-most", we check if // moving over to the right one spot brings us to the // end of the candidate parent's list + const auto* next_top_node = *post_order_iteration.top(); if ((++prev_top_handle) != next_top_node->get_ordered_children().end()) { push_until_left_most_found(); }