Skip to content

graphics/deko3d: fix and simplify rbtree code #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void CIntrusiveTreeBase::remove(N* node)
}
else
{
child = node->left() ? node->right() : node->left();
child = node->left() ? node->left() : node->right();
parent = node->getParent();
color = node->getColor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class CIntrusiveTree final : protected CIntrusiveTreeBase

T* first() const { return toType(minmax(N::Left)); }
T* last() const { return toType(minmax(N::Right)); }
bool empty() const { return m_root != nullptr; }
bool empty() const { return m_root == nullptr; }
void clear() { m_root = nullptr; }

T* prev(T* node) const { return toType(walk(toNode(node), N::Left)); }
Expand All @@ -194,31 +194,11 @@ class CIntrusiveTree final : protected CIntrusiveTreeBase
mode != UpperBound ? N::Left : N::Right,
[&lambda](N* curnode) { return lambda(toType(curnode)); });

switch (mode)
{
default:
case Exact:
break;
case LowerBound:
if (!node && parent)
{
if (&parent->left() == &point)
node = parent;
else
node = walk(parent, N::Right);
}
break;
case UpperBound:
if (node)
node = walk(node, N::Right);
else if (parent)
{
if (&parent->right() == &point)
node = walk(parent, N::Right);
else
node = parent;
}
break;
if (mode != Exact) {
if (mode == UpperBound && node)
node = walk(node, N::Right);
else if (!node && parent)
node = &parent->left() == &point ? parent : walk(parent, N::Right);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ternary actually correct for UpperBound mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let me know if there is any problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was mostly asking how did you arrive to that simplification, as I'm currently struggling to wrap my head around this code :p

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some analysis, I believe this code to be correct.

}
return toType(node);
}
Expand Down