Skip to content

Commit

Permalink
Change function Add and Delete to accept multiple Intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
b97tsk committed Jan 23, 2024
1 parent 741616c commit c666777
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions intervalset.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ func Collect[E Elem[E]](x Set[E], s ...Interval[E]) Set[E] {
return x
}

// Add adds range [r.Low, r.High) into x, returning the modified Set.
func Add[E Elem[E]](x Set[E], r Interval[E]) Set[E] {
return addRange(x, r.Low, r.High)
// Add adds zero or more Intervals into x, returning the modified Set.
func Add[E Elem[E]](x Set[E], s ...Interval[E]) Set[E] {
for _, r := range s {
x = addRange(x, r.Low, r.High)
}

return x
}

// addRange adds range [lo, hi) into x, returning the modified Set.
Expand Down Expand Up @@ -164,9 +168,13 @@ func addRange[E Elem[E]](x Set[E], lo, hi E) Set[E] {
return slices.Replace(x, i, j, Range(lo, hi))
}

// Delete removes range [r.Low, r.High) from x, returning the modified Set.
func Delete[E Elem[E]](x Set[E], r Interval[E]) Set[E] {
return deleteRange(x, r.Low, r.High)
// Delete removes zero or more Intervals from x, returning the modified Set.
func Delete[E Elem[E]](x Set[E], s ...Interval[E]) Set[E] {
for _, r := range s {
x = deleteRange(x, r.Low, r.High)
}

return x
}

// deleteRange removes range [lo, hi) from x, returning the modified Set.
Expand Down

0 comments on commit c666777

Please sign in to comment.