MCPcopy Index your code
hub / github.com/coder/coder / UniqueAndClear

Method UniqueAndClear

coderd/workspacestats/tracker.go:214–233  ·  view source on GitHub ↗

UniqueAndClear returns the unique set of entries in s and resets the internal map.

()

Source from the content-addressed store, hash-verified

212// UniqueAndClear returns the unique set of entries in s and
213// resets the internal map.
214func (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}

Callers 1

flushMethod · 0.80

Calls 3

CompareMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected