Order and visibility tracking algorithm (e.g. scope visibility)
I came up with a cleaner looking solution:

bool isVisibleTo(Node * accessor) {
    Node * node = accessor;
    while (node) {
        if (node == this) return true;
        if (node-&gt;_parent) {
            uint i = node-&gt;_parent-&gt;_children.indexOf(node);
            while (i) if (node-&gt;_parent-&gt;_children.at(--i) == this) return true;
        } node = node-&gt;_parent;
    } return false;
}


But it will be inevitably slower in a scenario with lots of children. While the first "messy" solution uses the relative tree indices and only traverses the object tree from child to parent, this cleaner solution goes through all children nodes before going to the parent. I will have to do some profiling with a bigger tree to verify if that is the case.

EDIT: I take it back, despite what appeared as an obvious performance penalty this method is actually about 4 times faster consistently. I tested with a whooping 10 million nodes