Returns a new set with items that exist only in both sets.
(other StringSet)
| 83 | |
| 84 | // Returns a new set with items that exist only in both sets. |
| 85 | func (set StringSet) Intersect(other StringSet) StringSet { |
| 86 | intersection := NewStringSet() |
| 87 | // loop over smaller set |
| 88 | if set.Cardinality() < other.Cardinality() { |
| 89 | for elem := range set { |
| 90 | if other.Contains(elem) { |
| 91 | intersection.Add(elem) |
| 92 | } |
| 93 | } |
| 94 | } else { |
| 95 | for elem := range other { |
| 96 | if set.Contains(elem) { |
| 97 | intersection.Add(elem) |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | return intersection |
| 102 | } |
| 103 | |
| 104 | // Returns a new set with items in the current set but not in the other set |
| 105 | func (set StringSet) Difference(other StringSet) StringSet { |