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();
}
// 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) {
+ post_order_iteration.push(iter.base());
+ }
}
}
// 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();
}
private:
using node_handle = std::list<WakeupTreeNode*>::iterator;
+ /**
+ * @brief A list which is used to "store" the root node of the traversed
+ * wakeup tree
+ *
+ * The root node is, by definition, not the child of any other node. This
+ * means that the root node also is contained in any list into which the
+ * iterator can generate a pointer (iterator). This list takes the role
+ * of allowing the iterator to treat the root node like any other.
+ */
+ std::list<WakeupTreeNode*> root_list;
+
/**
* @brief The current "view" of the iteration in post-order traversal
*/
std::stack<node_handle> post_order_iteration;
/**
- *
+ * @brief Search the wakeup tree until a leaf node appears at the front
+ * of the iteration, pushing all children towards the top of the stack
+ * as the search progresses
*/
void push_until_left_most_found();