Skip to content

Commit

Permalink
Rename function Combine to Reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
b97tsk committed Jan 23, 2024
1 parent c666777 commit 5f64dfd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions difference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func TestDifference(t *testing.T) {
Set[E]{{1, 5}, {9, 13}, {17, 21}, {25, 29}}.Difference(Set[E]{{5, 25}}),
Set[E]{{1, 5}, {25, 29}},
},
{Combine(Difference[E]), Set[E]{}},
{Combine(Difference, Set[E]{}), Set[E]{}},
{Reduce(Difference[E]), Set[E]{}},
{Reduce(Difference, Set[E]{}), Set[E]{}},
{
func() Set[E] {
var x2, x3, x5 Set[E]
Expand All @@ -79,7 +79,7 @@ func TestDifference(t *testing.T) {
x5 = Add(x5, One(E(i)))
}

return Combine(Difference, x2, x3, x5)
return Reduce(Difference, x2, x3, x5)
}(),
Set[E]{{2, 3}, {4, 5}, {8, 9}, {14, 15}, {16, 17}, {22, 23}, {26, 27}, {28, 29}},
},
Expand Down
6 changes: 3 additions & 3 deletions intersection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestIntersection(t *testing.T) {
Set[E]{{3, 11}, {13, 21}}.Intersection(Set[E]{{1, 5}, {9, 15}, {19, 23}}),
Set[E]{{3, 5}, {9, 11}, {13, 15}, {19, 21}},
},
{Combine(Intersection[E]), Set[E]{}},
{Combine(Intersection, Set[E]{}), Set[E]{}},
{Reduce(Intersection[E]), Set[E]{}},
{Reduce(Intersection, Set[E]{}), Set[E]{}},
{
func() Set[E] {
var x2, x3, x5 Set[E]
Expand All @@ -43,7 +43,7 @@ func TestIntersection(t *testing.T) {
x5 = Add(x5, One(E(i)))
}

return Combine(Intersection, x2, x3, x5)
return Reduce(Intersection, x2, x3, x5)
}(),
Set[E]{{30, 31}, {60, 61}, {90, 91}},
},
Expand Down
4 changes: 2 additions & 2 deletions combine.go → reduce.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package intervals

// Combine applies set operation op over sets, returning the end result.
// Reduce applies set operation op over sets, returning the end result.
// op can be any of [Difference], [Intersection], [SymmetricDifference] and
// [Union].
func Combine[E Elem[E]](
func Reduce[E Elem[E]](
op func(z, x, y Set[E]) Set[E],
sets ...Set[E],
) Set[E] {
Expand Down
6 changes: 3 additions & 3 deletions symdiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func TestSymmetricDifference(t *testing.T) {
Set[E]{{1, 5}, {9, 13}, {17, 21}, {25, 29}}.SymmetricDifference(Set[E]{{5, 25}}),
Set[E]{{1, 9}, {13, 17}, {21, 29}},
},
{Combine(SymmetricDifference[E]), Set[E]{}},
{Combine(SymmetricDifference, Set[E]{}), Set[E]{}},
{Reduce(SymmetricDifference[E]), Set[E]{}},
{Reduce(SymmetricDifference, Set[E]{}), Set[E]{}},
{
func() Set[E] {
var x2, x3, x5 Set[E]
Expand All @@ -79,7 +79,7 @@ func TestSymmetricDifference(t *testing.T) {
x5 = Add(x5, One(E(i)))
}

return Combine(SymmetricDifference, x2, x3, x5)
return Reduce(SymmetricDifference, x2, x3, x5)
}(),
Set[E]{{2, 6}, {8, 10}, {14, 15}, {16, 17}, {21, 23}, {25, 29}, {30, 31}},
},
Expand Down
6 changes: 3 additions & 3 deletions union_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestUnion(t *testing.T) {
Set[E]{{3, 11}, {13, 21}}.Union(Set[E]{{1, 5}, {9, 15}, {19, 23}}),
Set[E]{{1, 23}},
},
{Combine(Union[E]), Set[E]{}},
{Combine(Union, Set[E]{}), Set[E]{}},
{Reduce(Union[E]), Set[E]{}},
{Reduce(Union, Set[E]{}), Set[E]{}},
{
func() Set[E] {
var x2, x3, x5 Set[E]
Expand All @@ -51,7 +51,7 @@ func TestUnion(t *testing.T) {
x5 = Add(x5, One(E(i)))
}

return Combine(Union, x2, x3, x5)
return Reduce(Union, x2, x3, x5)
}(),
Set[E]{{2, 7}, {8, 11}, {12, 13}, {14, 17}, {18, 19}, {20, 23}, {24, 29}, {30, 31}},
},
Expand Down

0 comments on commit 5f64dfd

Please sign in to comment.