Insert adds an interval to the tree. Returns true if the interval was added, false if it was a duplicate.
(interval ast.Interval)
| 46 | // Insert adds an interval to the tree. |
| 47 | // Returns true if the interval was added, false if it was a duplicate. |
| 48 | func (t *IntervalTree) Insert(interval ast.Interval) bool { |
| 49 | // Check for duplicate |
| 50 | if t.contains(interval) { |
| 51 | return false |
| 52 | } |
| 53 | |
| 54 | t.root = t.insert(t.root, interval) |
| 55 | t.size++ |
| 56 | return true |
| 57 | } |
| 58 | |
| 59 | // insert recursively inserts an interval and rebalances. |
| 60 | func (t *IntervalTree) insert(node *treeNode, interval ast.Interval) *treeNode { |