From 5f64dfdebff2a18b2d99d809951fee39eceb461e Mon Sep 17 00:00:00 2001 From: b97tsk Date: Tue, 23 Jan 2024 20:20:17 +0800 Subject: [PATCH] Rename function Combine to Reduce --- difference_test.go | 6 +++--- intersection_test.go | 6 +++--- combine.go => reduce.go | 4 ++-- symdiff_test.go | 6 +++--- union_test.go | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) rename combine.go => reduce.go (83%) diff --git a/difference_test.go b/difference_test.go index d4383c5..69ade84 100644 --- a/difference_test.go +++ b/difference_test.go @@ -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] @@ -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}}, }, diff --git a/intersection_test.go b/intersection_test.go index 3d33fb8..0472f4b 100644 --- a/intersection_test.go +++ b/intersection_test.go @@ -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] @@ -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}}, }, diff --git a/combine.go b/reduce.go similarity index 83% rename from combine.go rename to reduce.go index 1f10bcc..53a04b2 100644 --- a/combine.go +++ b/reduce.go @@ -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] { diff --git a/symdiff_test.go b/symdiff_test.go index db961d0..ae77f02 100644 --- a/symdiff_test.go +++ b/symdiff_test.go @@ -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] @@ -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}}, }, diff --git a/union_test.go b/union_test.go index cc3aa03..3f90304 100644 --- a/union_test.go +++ b/union_test.go @@ -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] @@ -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}}, },