WalkUpParent calls the given function on all of the node's parents (but not the node itself), sequentially in the current goroutine (generally necessary for going up, which is typically quite fast anyway). It stops walking if the function returns [Break] and keeps walking if it returns [Continue]. I
(fun func(n Node) bool)
| 461 | // function returns [Break] and keeps walking if it returns [Continue]. It returns |
| 462 | // whether walking was finished (false if it was aborted with [Break]). |
| 463 | func (n *NodeBase) WalkUpParent(fun func(n Node) bool) bool { |
| 464 | if IsRoot(n) { |
| 465 | return true |
| 466 | } |
| 467 | cur := n.Parent |
| 468 | for { |
| 469 | if !fun(cur) { // false return means stop |
| 470 | return false |
| 471 | } |
| 472 | parent := cur.AsTree().Parent |
| 473 | if parent == nil || parent == cur { // prevent loops |
| 474 | return true |
| 475 | } |
| 476 | cur = parent |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | // WalkDown strategy: https://stackoverflow.com/questions/5278580/non-recursive-depth-first-search-algorithm |
| 481 |
no test coverage detected