Intersection returns a new set which includes the item in BOTH s1 and s2 For example: s1 = {a1, a2} s2 = {a2, a3} s1.Intersection(s2) = {a2}
(s2 String)
| 124 | // s2 = {a2, a3} |
| 125 | // s1.Intersection(s2) = {a2} |
| 126 | func (s1 String) Intersection(s2 String) String { |
| 127 | var walk, other String |
| 128 | result := NewString() |
| 129 | if s1.Len() < s2.Len() { |
| 130 | walk = s1 |
| 131 | other = s2 |
| 132 | } else { |
| 133 | walk = s2 |
| 134 | other = s1 |
| 135 | } |
| 136 | for key := range walk { |
| 137 | if other.Has(key) { |
| 138 | result.Insert(key) |
| 139 | } |
| 140 | } |
| 141 | return result |
| 142 | } |
| 143 | |
| 144 | // IsSuperset returns true if and only if s1 is a superset of s2. |
| 145 | func (s1 String) IsSuperset(s2 String) bool { |