gopl icon indicating copy to clipboard operation
gopl copied to clipboard

Ex6.3 IntersectWith and DifferenceWith

Open songjiyang opened this issue 5 years ago • 2 comments

IntersectWith and DifferenceWith is wrong, you should not append tword where i > len(s.words), test code below

var m, n IntSet
m.AddAll(1,3,5)
n.AddAll(1,2,5, 100, 1000)
fmt.Println("m:", &m)
fmt.Println("n:", &n)
//m.IntersectWith(&n)
//fmt.Println("After m.IntersectWith(&n) m:", &m)
m.DifferenceWith(&n)
fmt.Println("After m.DifferenceWith(&n) m:", &m)

//m: {1 3 5}
//n: {1 2 5 100 1000}
//After m.DifferenceWith(&n) m: {3 100 1000}
//m: {1 3 5}
//n: {1 2 5 100 1000}
//After m.IntersectWith(&n) m: {1 5 100 1000}

songjiyang avatar Dec 28 '19 08:12 songjiyang

agree

zeliangchu avatar Apr 28 '21 09:04 zeliangchu

Not only this, we shall clear s[i] data where i >= len(t.words)

soon1995 avatar Apr 19 '23 16:04 soon1995