(st2 Set[T])
| 124 | } |
| 125 | |
| 126 | func (st *set[T]) Intersection(st2 Set[T]) Set[T] { |
| 127 | intersectionSet := New[T]() |
| 128 | var minSet, maxSet Set[T] |
| 129 | if st.Len() > st2.Len() { |
| 130 | minSet = st2 |
| 131 | maxSet = st |
| 132 | } else { |
| 133 | minSet = st |
| 134 | maxSet = st2 |
| 135 | } |
| 136 | for _, item := range minSet.GetItems() { |
| 137 | if maxSet.In(item) { |
| 138 | intersectionSet.Add(item) |
| 139 | } |
| 140 | } |
| 141 | return intersectionSet |
| 142 | } |
| 143 | |
| 144 | func (st *set[T]) Difference(st2 Set[T]) Set[T] { |
| 145 | differenceSet := New[T]() |