From 5e029031cc2f71fd440cd42470047a079308d96d Mon Sep 17 00:00:00 2001 From: AlexNg Date: Tue, 3 Sep 2024 01:53:53 +0800 Subject: [PATCH] feat: Implement Set.Copy() Signed-off-by: AlexNg --- cmd/utils/types/set.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/utils/types/set.go b/cmd/utils/types/set.go index 7046aa5..9835189 100644 --- a/cmd/utils/types/set.go +++ b/cmd/utils/types/set.go @@ -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)