NewExecutionSegmentSequenceFromString parses strings of the format "r1,r2,r3,...,rn", which represents the sequences like (r1, r2], (r2, r3], (r3, r4], ..., (r{n-1}, rn].
(strSeq string)
| 322 | // "r1,r2,r3,...,rn", which represents the sequences like (r1, r2], (r2, r3], |
| 323 | // (r3, r4], ..., (r{n-1}, rn]. |
| 324 | func NewExecutionSegmentSequenceFromString(strSeq string) (ExecutionSegmentSequence, error) { |
| 325 | if len(strSeq) == 0 { |
| 326 | return nil, nil |
| 327 | } |
| 328 | |
| 329 | points := strings.Split(strSeq, ",") |
| 330 | if len(points) < 2 { |
| 331 | return nil, fmt.Errorf("at least 2 points are needed for an execution segment sequence, %d given", len(points)) |
| 332 | } |
| 333 | var start *big.Rat |
| 334 | |
| 335 | segments := make([]*ExecutionSegment, 0, len(points)-1) |
| 336 | for i, point := range points { |
| 337 | rat, err := stringToRat(point) |
| 338 | if err != nil { |
| 339 | return nil, err |
| 340 | } |
| 341 | if i == 0 { |
| 342 | start = rat |
| 343 | continue |
| 344 | } |
| 345 | |
| 346 | segment, err := NewExecutionSegment(start, rat) |
| 347 | if err != nil { |
| 348 | return nil, err |
| 349 | } |
| 350 | segments = append(segments, segment) |
| 351 | start = rat |
| 352 | } |
| 353 | |
| 354 | return NewExecutionSegmentSequence(segments...) |
| 355 | } |
| 356 | |
| 357 | // UnmarshalText implements the encoding.TextUnmarshaler interface, so that |
| 358 | // execution segment sequences can be specified as CLI flags, environment |
searching dependent graphs…