Parents: IndexInParent returns our index within our parent node. It caches the last value and uses that for an optimized search so subsequent calls are typically quite fast. Returns -1 if we don't have a parent.
()
| 147 | // last value and uses that for an optimized search so subsequent calls |
| 148 | // are typically quite fast. Returns -1 if we don't have a parent. |
| 149 | func (n *NodeBase) IndexInParent() int { |
| 150 | if n.Parent == nil { |
| 151 | return -1 |
| 152 | } |
| 153 | idx := IndexOf(n.Parent.AsTree().Children, n.This, n.index) // very fast if index is close |
| 154 | n.index = idx |
| 155 | return idx |
| 156 | } |
| 157 | |
| 158 | // ParentLevel finds a given potential parent node recursively up the |
| 159 | // hierarchy, returning the level above the current node that the parent was |
no test coverage detected