matlab-tree
matlab-tree copied to clipboard
conditioniterator adds root node even if it doesn't satisfy condition
If one calls t.conditioniterator(n, condition) and node n does not satisfy the condition, it will still get added to the returned list of IDs, because of the following code:
function val = recurse(node)
val = node; % <--- first, node is added...
content = obj.Node{val};
if obj.isleaf(node) || ~condition(content) % ...THEN, the condition is checked
return
else
% bla
This only happens for the node passed as argument (the "root" of the traversal). For subsequent nodes visited in the function, they are checked before the recursive call. Which, incidentally, makes the above bolded check redundant. So it seems the solution is to remove the redundant check.