You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't think it has to be that expensive. Red-black tree properties are:
Every node is either red or black.
The root node must be black.
All leaf nodes (null or NIL nodes) are considered black.
If a node is red, then both its children must be black (no two consecutive red nodes).
Every path from a given node to any of its descendant leaf nodes contains the same number of black nodes.
It should be possible to check all of these not only in linear time, but in one pass over the tree. Current implementation seems to be checking the 5th item twice:
using blackHeight recursive function (linear)
using leafCollector + the loop in the end of the function (lines 75-97). This is $O(n^2)$, since it recomputes paths from the leaves to each node again and again.
The second is ineffective and redundant. Removing it and moving all per-node checks inside the function which traverses a tree allows running all checks in one pass. This should allow running tree violation checks more often in unit tests. I will prepare a PR shortly.
It's #69. This does not include any changes to existing tests, nor does it convert std::function to a lambda which would make it even faster (I'm not sure if you like the syntax of self-passing lambdas).
It's #69. This does not include any changes to existing tests, nor does it convert std::function to a lambda which would make it even faster (I'm not sure if you like the syntax of self-passing lambdas).
I like any good technique, even if a bit overkill. As long as the compile checks still run fine. (EDIT: And it doesnt blow up debug symbols and binary size, i have burnt myself with template Matryoshka :D - not applicable here, just saying)
As said in the PR, I will review this within the next days.
Activity
odorovskoy commentedon Aug 30, 2026
It's #69. This does not include any changes to existing tests, nor does it convert
std::functionto a lambda which would make it even faster (I'm not sure if you like the syntax of self-passing lambdas).5cript commentedon Aug 30, 2026
I like any good technique, even if a bit overkill. As long as the compile checks still run fine. (EDIT: And it doesnt blow up debug symbols and binary size, i have burnt myself with template Matryoshka :D - not applicable here, just saying)
As said in the PR, I will review this within the next days.
5cript commentedon Aug 31, 2026
Resolved with #69