From f6def15e416c2e1a5419e92ba3488a30d0f4108c Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Mon, 2 Jun 2025 20:14:22 +0100 Subject: [PATCH] set: introduce set intersection Change-Id: squuuywunnkllwmqxymormkywzxpppzp Signed-off-by: oppiliappan --- set.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/set.go b/set.go index eca34a3..2698c91 100644 --- a/set.go +++ b/set.go @@ -33,3 +33,14 @@ func (s Set[T]) Union(other Set[T]) Set[T] { } return result } + +// Intersection returns a new set containing elements common to s and other. +func (s Set[T]) Intersection(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