diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-05 07:49:02 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-04-05 07:49:02 -0600 |
commit | 68eb7a16b9759646619a7d9dec2b62fa9d0c30cf (patch) | |
tree | 8bb4b70337a299f1dacb3c2858210d4bf6bd4b04 /lib/maps/maputil.go | |
parent | b0f290078d531d2dcb5d34e809b0711ce9b6491e (diff) | |
parent | d7dd6dfd7aeb40f06ff4fbe7f906d8feed64b95f (diff) |
Merge branch 'lukeshu/misc'
Diffstat (limited to 'lib/maps/maputil.go')
-rw-r--r-- | lib/maps/maputil.go | 17 |
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 +} |