mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
LibWeb: Add TreeNode<T>::next_in_pre_order(T* stay_within) variant
This is a scoped variant of the pre-order traversal helper that aborts when attempting to leave the `stay_within` node.
This commit is contained in:
parent
1ce6c49f5e
commit
9358f108c4
1 changed files with 20 additions and 0 deletions
|
@ -140,11 +140,31 @@ public:
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
T* next_in_pre_order(T const* stay_within)
|
||||||
|
{
|
||||||
|
if (first_child())
|
||||||
|
return first_child();
|
||||||
|
|
||||||
|
T* node = static_cast<T*>(this);
|
||||||
|
T* next = nullptr;
|
||||||
|
while (!(next = node->next_sibling())) {
|
||||||
|
node = node->parent();
|
||||||
|
if (!node || node == stay_within)
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
T const* next_in_pre_order() const
|
T const* next_in_pre_order() const
|
||||||
{
|
{
|
||||||
return const_cast<TreeNode*>(this)->next_in_pre_order();
|
return const_cast<TreeNode*>(this)->next_in_pre_order();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
T const* next_in_pre_order(T const* stay_within) const
|
||||||
|
{
|
||||||
|
return const_cast<TreeNode*>(this)->next_in_pre_order(stay_within);
|
||||||
|
}
|
||||||
|
|
||||||
T* previous_in_pre_order()
|
T* previous_in_pre_order()
|
||||||
{
|
{
|
||||||
if (auto* node = previous_sibling()) {
|
if (auto* node = previous_sibling()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue