From dfe2750f6d40d23c0ae3d11cf62d0a8055a84586 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Mon, 2 Jun 2025 20:14:22 +0100 Subject: [PATCH] set: introduce set difference Change-Id: soqmukrvportotypoxnrtulytlllznxm Signed-off-by: oppiliappan --- set.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/set.go b/set.go index bd0dbda..f4c0b61 100644 --- a/set.go +++ b/set.go @@ -44,3 +44,14 @@ func (s Set[T]) Intersection(other Set[T]) Set[T] { } return result } + +// Difference returns a new set with elements in s but not in other. +func (s Set[T]) Difference(other Set[T]) Set[T] { + result := New[T]() + for k := range s { + if _, ok := other[k]; !ok { + result.Add(k) + } + } + return result +} -- 2.43.0