From c1578391cc2089cd224fd8325c333038e0ba7b7b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 31 Mar 2023 18:01:47 -0600 Subject: maps: Add HasKey and HaveAnyKeysInCommon functions, use them --- lib/containers/set.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'lib/containers') diff --git a/lib/containers/set.go b/lib/containers/set.go index 074d126..af13d50 100644 --- a/lib/containers/set.go +++ b/lib/containers/set.go @@ -138,20 +138,11 @@ func (o Set[T]) TakeOne() T { } func (o Set[T]) Has(v T) bool { - _, has := o[v] - return has + return maps.HasKey(o, v) } -func (small Set[T]) HasAny(big Set[T]) bool { - if len(big) < len(small) { - small, big = big, small - } - for v := range small { - if _, ok := big[v]; ok { - return true - } - } - return false +func (a Set[T]) HasAny(b Set[T]) bool { + return maps.HaveAnyKeysInCommon(a, b) } func (small Set[T]) Intersection(big Set[T]) Set[T] { @@ -160,7 +151,7 @@ func (small Set[T]) Intersection(big Set[T]) Set[T] { } ret := make(Set[T]) for v := range small { - if _, ok := big[v]; ok { + if maps.HasKey(big, v) { ret.Insert(v) } } -- cgit v1.2.3-2-g168b