diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-31 18:01:47 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-04 14:08:38 -0600 |
commit | c1578391cc2089cd224fd8325c333038e0ba7b7b (patch) | |
tree | eb003ba90cb0f8b1863167dec670b4ef0f80f29a /lib/containers/set.go | |
parent | 1ba83231195ea3b78ce545f4518f70c74819345b (diff) |
maps: Add HasKey and HaveAnyKeysInCommon functions, use them
Diffstat (limited to 'lib/containers/set.go')
-rw-r--r-- | lib/containers/set.go | 17 |
1 files changed, 4 insertions, 13 deletions
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) } } |