Skip to content

Commit

Permalink
Remove method Contains(One|Range)
Browse files Browse the repository at this point in the history
  • Loading branch information
b97tsk committed Jan 24, 2024
1 parent 7ab9cd1 commit a99a373
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
15 changes: 2 additions & 13 deletions intervalset.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,8 @@ func deleteRange[E Elem[E]](x Set[E], lo, hi E) Set[E] {

// Contains reports whether x contains every element in range [r.Low, r.High).
func (x Set[E]) Contains(r Interval[E]) bool {
return x.ContainsRange(r.Low, r.High)
}

// ContainsOne reports whether x contains a single element v.
func (x Set[E]) ContainsOne(v E) bool {
i := sort.Search(len(x), func(i int) bool { return x[i].High.Compare(v) > 0 })
return i < len(x) && x[i].Low.Compare(v) <= 0
}

// ContainsRange reports whether x contains every element in range [lo, hi).
func (x Set[E]) ContainsRange(lo, hi E) bool {
i := sort.Search(len(x), func(i int) bool { return x[i].High.Compare(lo) > 0 })
return i < len(x) && x[i].Low.Compare(lo) <= 0 && x[i].High.Compare(hi) >= 0 && lo.Compare(hi) < 0
i := sort.Search(len(x), func(i int) bool { return x[i].High.Compare(r.Low) > 0 })
return i < len(x) && x[i].Low.Compare(r.Low) <= 0 && x[i].High.Compare(r.High) >= 0 && r.Low.Compare(r.High) < 0
}

// Equal reports whether x is identical to y.
Expand Down
16 changes: 8 additions & 8 deletions intervalset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ func TestContains(t *testing.T) {
s := Set[E]{{1, 3}, {5, 7}}

assertions := []bool{
s.ContainsOne(0) == false,
s.ContainsOne(1) == true,
s.ContainsOne(2) == true,
s.ContainsOne(3) == false,
s.ContainsOne(4) == false,
s.ContainsOne(5) == true,
s.ContainsOne(6) == true,
s.ContainsOne(7) == false,
s.Contains(One[E](0)) == false,
s.Contains(One[E](1)) == true,
s.Contains(One[E](2)) == true,
s.Contains(One[E](3)) == false,
s.Contains(One[E](4)) == false,
s.Contains(One[E](5)) == true,
s.Contains(One[E](6)) == true,
s.Contains(One[E](7)) == false,
s.Contains(Range[E](1, 3)) == true,
s.Contains(Range[E](3, 5)) == false,
s.Contains(Range[E](5, 7)) == true,
Expand Down

0 comments on commit a99a373

Please sign in to comment.