Skip to content

Commit

Permalink
sets: address review comments
Browse files Browse the repository at this point in the history
Part of PCI-3790
  • Loading branch information
marco-m-pix4d committed May 14, 2024
1 parent b5e3030 commit f089921
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions sets/sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,14 @@ func (s *Set[T]) Difference(x *Set[T]) *Set[T] {
func (s *Set[T]) Intersection(x *Set[T]) *Set[T] {
result := New[T](0)
// loop over the smaller set (thanks to https://github.com/deckarep/golang-set)
if s.Size() < x.Size() {
for item := range s.items {
if x.Contains(item) {
result.items[item] = struct{}{}
}
}
} else {
for item := range x.items {
if s.Contains(item) {
result.items[item] = struct{}{}
}
smaller := s
bigger := x
if smaller.Size() > bigger.Size() {
smaller, bigger = bigger, smaller
}
for item := range smaller.items {
if bigger.Contains(item) {
result.items[item] = struct{}{}
}
}
return result
Expand Down

0 comments on commit f089921

Please sign in to comment.