Skip to content

Commit

Permalink
exsync: add Set.AsList
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 3, 2024
1 parent 8be1436 commit 9e0c1c2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions exsync/syncset.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,18 @@ func (s *Set[T]) Size() int {
s.l.RUnlock()
return size
}

func (s *Set[T]) AsList() []T {
if s == nil {
return nil
}
s.l.RLock()
list := make([]T, len(s.m))
i := 0
for item := range s.m {
list[i] = item
i++
}
s.l.RUnlock()
return list
}

0 comments on commit 9e0c1c2

Please sign in to comment.