insertLoop adds the given loop to the loop map under the specified parent. All children of the new entry are checked to see if the need to move up to a different level.
(newLoop, parent *Loop)
| 307 | // All children of the new entry are checked to see if the need to move up to |
| 308 | // a different level. |
| 309 | func (lm loopMap) insertLoop(newLoop, parent *Loop) { |
| 310 | var children []*Loop |
| 311 | for done := false; !done; { |
| 312 | children = lm[parent] |
| 313 | done = true |
| 314 | for _, child := range children { |
| 315 | if child.ContainsNested(newLoop) { |
| 316 | parent = child |
| 317 | done = false |
| 318 | break |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | // Now, we have found a parent for this loop, it may be that some of the |
| 324 | // children of the parent of this loop may now be children of the new loop. |
| 325 | newChildren := lm[newLoop] |
| 326 | for i := 0; i < len(children); { |
| 327 | child := children[i] |
| 328 | if newLoop.ContainsNested(child) { |
| 329 | newChildren = append(newChildren, child) |
| 330 | children = append(children[0:i], children[i+1:]...) |
| 331 | } else { |
| 332 | i++ |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | lm[newLoop] = newChildren |
| 337 | lm[parent] = append(children, newLoop) |
| 338 | } |
| 339 | |
| 340 | // loopStack simplifies access to the loops while being initialized. |
| 341 | type loopStack []*Loop |
no test coverage detected