Skip to content

Commit

Permalink
feat: Implement Set.Copy()
Browse files Browse the repository at this point in the history
Signed-off-by: AlexNg <[email protected]>
  • Loading branch information
caffeine-addictt committed Sep 2, 2024
1 parent 488298c commit 5e02903
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/utils/types/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ func (s *Set[T]) Contains(item T) bool {
return ok
}

// Copy returns a new set containing all items in the set
func (s *Set[T]) Copy() Set[T] {
n := make(Set[T], len(*s))
for k := range *s {
n[k] = struct{}{}
}
return n
}

// Count returns the number of items in the set
func (s *Set[T]) Len() int {
return len(*s)
Expand Down

0 comments on commit 5e02903

Please sign in to comment.