InsertWithoutMergingRange inserts the given segment into the set and returns an iterator to the inserted segment. All existing iterators (excluding the returned iterator) are invalidated. If the new segment would overlap an existing segment, or if r is invalid, InsertWithoutMergingRange panics. In
(r Range, val Value)
| 488 | // needs to do additional work between finding the gap and insertion, use |
| 489 | // InsertWithoutMerging instead. |
| 490 | func (s *Set) InsertWithoutMergingRange(r Range, val Value) Iterator { |
| 491 | if r.Length() <= 0 { |
| 492 | panic(fmt.Sprintf("invalid segment range %v", r)) |
| 493 | } |
| 494 | seg, gap := s.Find(r.Start) |
| 495 | if seg.Ok() { |
| 496 | panic(fmt.Sprintf("new segment %v overlaps existing segment %v", r, seg.Range())) |
| 497 | } |
| 498 | if gap.End() < r.End { |
| 499 | panic(fmt.Sprintf("new segment %v overlaps existing segment %v", r, gap.NextSegment().Range())) |
| 500 | } |
| 501 | return s.InsertWithoutMerging(gap, r, val) |
| 502 | } |
| 503 | |
| 504 | // TryInsertRange attempts to insert the given segment into the set. If the new |
| 505 | // segment can be merged with adjacent segments, TryInsertRange will do so. |