chore: Rename Contains to IsSupersetOf (#63062)

The name Contains is also commonly used for checking if a
set contains an element in other languages, so it leads to
confusing auto-complete. Additionally, IsSupersetOf sounds
more expensive, which may be the case for this operation.
This commit is contained in:
Varun Gandhi 2024-06-04 17:14:19 +08:00 committed by GitHub
parent 5915788ef0
commit e55003da89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 10 deletions

View File

@ -83,8 +83,8 @@ func (s Set[T]) Intersect(b Set[T]) Set[T] {
return Intersection(s, b)
}
// Contains returns true if s has all the elements in b.
func (s Set[T]) Contains(b Set[T]) bool {
// IsSupersetOf returns true if s has all the elements in b.
func (s Set[T]) IsSupersetOf(b Set[T]) bool {
// do not waste time on loop if b is bigger than s
if len(b) > len(s) {
return false

View File

@ -65,16 +65,16 @@ func TestSet(t *testing.T) {
require.Equal(t, []int{1}, s.Values())
})
t.Run("Contains returns true if set contains the other set", func(t *testing.T) {
require.True(t, a.Contains(NewSet(1, 2)))
require.True(t, a.Contains(NewSet(1, 2, 3)))
require.False(t, a.Contains(b))
t.Run("IsSupersetOf returns true if set contains the other set", func(t *testing.T) {
require.True(t, a.IsSupersetOf(NewSet(1, 2)))
require.True(t, a.IsSupersetOf(NewSet(1, 2, 3)))
require.False(t, a.IsSupersetOf(b))
// set always contains self
require.True(t, a.Contains(a))
// a set is a superset of itself
require.True(t, a.IsSupersetOf(a))
// empty set is always contained
require.True(t, a.Contains(NewSet[int]()))
// a set is always the superset of an empty set
require.True(t, a.IsSupersetOf(NewSet[int]()))
})
t.Run("Union creates a new set with all values from both sets", func(t *testing.T) {