| 61 | } |
| 62 | |
| 63 | func (n *Edge) Insert(node Node) { |
| 64 | // If Left is nil, always simply insert the node |
| 65 | if n.NodeLeft == nil { |
| 66 | node.SetParent(n) |
| 67 | n.NodeLeft = node |
| 68 | |
| 69 | return |
| 70 | } |
| 71 | |
| 72 | // If Right is nil, insert the node |
| 73 | n.NodeRight = node |
| 74 | |
| 75 | // If the node to insert is an edge, set the parent |
| 76 | if node.Kind() == "edge" { |
| 77 | node.SetParent(n) |
| 78 | |
| 79 | return |
| 80 | } |
| 81 | |
| 82 | // If the node to insert is a leaf, send it to the sibling right |
| 83 | n.Parent.Right().Insert(node) |
| 84 | } |
| 85 | |
| 86 | func (n *Edge) HasSpace() bool { |
| 87 | return n.NodeLeft == nil || n.NodeRight == nil |