UniqueAndClear returns the unique set of entries in s and resets the internal map.
()
| 212 | // UniqueAndClear returns the unique set of entries in s and |
| 213 | // resets the internal map. |
| 214 | func (s *uuidSet) UniqueAndClear() []uuid.UUID { |
| 215 | s.l.Lock() |
| 216 | defer s.l.Unlock() |
| 217 | if s.m == nil { |
| 218 | s.m = make(map[uuid.UUID]struct{}) |
| 219 | return []uuid.UUID{} |
| 220 | } |
| 221 | l := make([]uuid.UUID, 0) |
| 222 | for k := range s.m { |
| 223 | l = append(l, k) |
| 224 | } |
| 225 | // For ease of testing, sort the IDs lexically |
| 226 | sort.Slice(l, func(i, j int) bool { |
| 227 | // For some unfathomable reason, byte arrays are not comparable? |
| 228 | // See https://github.com/golang/go/issues/61004 |
| 229 | return bytes.Compare(l[i][:], l[j][:]) < 0 |
| 230 | }) |
| 231 | clear(s.m) |
| 232 | return l |
| 233 | } |