summaryrefslogtreecommitdiff
path: root/lib/maps/maputil.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-03-31 18:01:47 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2023-04-04 14:08:38 -0600
commitc1578391cc2089cd224fd8325c333038e0ba7b7b (patch)
treeeb003ba90cb0f8b1863167dec670b4ef0f80f29a /lib/maps/maputil.go
parent1ba83231195ea3b78ce545f4518f70c74819345b (diff)
maps: Add HasKey and HaveAnyKeysInCommon functions, use them
Diffstat (limited to 'lib/maps/maputil.go')
-rw-r--r--lib/maps/maputil.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/maps/maputil.go b/lib/maps/maputil.go
index d409e70..63e52a0 100644
--- a/lib/maps/maputil.go
+++ b/lib/maps/maputil.go
@@ -25,3 +25,20 @@ func SortedKeys[K constraints.Ordered, V any](m map[K]V) []K {
slices.Sort(ret)
return ret
}
+
+func HasKey[K comparable, V any](m map[K]V, k K) bool {
+ _, has := m[k]
+ return has
+}
+
+func HaveAnyKeysInCommon[K comparable, V1, V2 any](small map[K]V1, big map[K]V2) bool {
+ if len(big) < len(small) {
+ return HaveAnyKeysInCommon(big, small)
+ }
+ for v := range small {
+ if _, ok := big[v]; ok {
+ return true
+ }
+ }
+ return false
+}