SDiff computes the difference between the first and subsequent sets. It returns keys unique to the first set and an error if applicable.
(keys ...string)
| 194 | // SDiff computes the difference between the first and subsequent sets. |
| 195 | // It returns keys unique to the first set and an error if applicable. |
| 196 | func (s *SetStructure) SDiff(keys ...string) ([]string, error) { |
| 197 | // If there are no keys, then there's no difference |
| 198 | if len(keys) == 0 { |
| 199 | return nil, nil |
| 200 | } |
| 201 | |
| 202 | first, err := s.checkAndGetSet(keys[0], false) |
| 203 | if err != nil { |
| 204 | return nil, err |
| 205 | } |
| 206 | |
| 207 | // Initialize a set for members of first set |
| 208 | mem := make(map[string]struct{}) |
| 209 | for k := range *first { |
| 210 | mem[k] = struct{}{} |
| 211 | } |
| 212 | |
| 213 | var diffMembers []string |
| 214 | // If member is in the first set and also in another set, remove it. |
| 215 | for _, key := range keys[1:] { |
| 216 | fs, err := s.checkAndGetSet(key, false) |
| 217 | if err != nil { |
| 218 | return nil, err |
| 219 | } |
| 220 | for k := range *fs { |
| 221 | // Only delete the existing members in the first set. Do not add members from other sets |
| 222 | delete(mem, k) |
| 223 | } |
| 224 | } |
| 225 | // Remaining members in mem are unique to first set. |
| 226 | for k := range mem { |
| 227 | diffMembers = append(diffMembers, k) |
| 228 | } |
| 229 | |
| 230 | return diffMembers, nil |
| 231 | } |
| 232 | |
| 233 | // Keys returns all the keys of the set structure |
| 234 | func (s *SetStructure) Keys(regx string) ([]string, error) { |
nothing calls this directly
no test coverage detected