From 914da8dc8f671e348b3a07db8b585b245c080aae Mon Sep 17 00:00:00 2001 From: soon Date: Thu, 20 Apr 2023 00:29:02 +0800 Subject: [PATCH] ex6.3: Fix InterceptWith and DifferenceWith --- ex6.3/intset.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ex6.3/intset.go b/ex6.3/intset.go index 04e2bbb..80c48ee 100644 --- a/ex6.3/intset.go +++ b/ex6.3/intset.go @@ -49,10 +49,11 @@ func (s *IntSet) IntersectWith(t *IntSet) { for i, tword := range t.words { if i < len(s.words) { s.words[i] &= tword - } else { - s.words = append(s.words, tword) } } + for i := len(t.words); i < len(s.words); i++ { + s.words[i] = 0 + } } // Set s to the difference of s and t. @@ -60,8 +61,6 @@ func (s *IntSet) DifferenceWith(t *IntSet) { for i, tword := range t.words { if i < len(s.words) { s.words[i] &^= tword - } else { - s.words = append(s.words, tword) } } }