From 93618842ae473c3daa246ccfc959b1d2710a3ada Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 12 Sep 2023 15:37:24 +0530 Subject: [PATCH] Make a couple of other Set API functions nil-safe --- tools/utils/set.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/utils/set.go b/tools/utils/set.go index 9965d0880..13daf694f 100644 --- a/tools/utils/set.go +++ b/tools/utils/set.go @@ -84,7 +84,7 @@ func (self *Set[T]) Intersect(other *Set[T]) (ans *Set[T]) { func (self *Set[T]) Subtract(other *Set[T]) (ans *Set[T]) { ans = NewSet[T](self.Len()) for x := range self.items { - if !other.Has(x) { + if other == nil || !other.Has(x) { ans.items[x] = struct{}{} } } @@ -92,6 +92,9 @@ func (self *Set[T]) Subtract(other *Set[T]) (ans *Set[T]) { } func (self *Set[T]) IsSubsetOf(other *Set[T]) bool { + if other == nil { + return self.Len() == 0 + } for x := range self.items { if !other.Has(x) { return false