MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / CollectDifferencesFromMaps

Function CollectDifferencesFromMaps

pkg/utils/operations.go:25–46  ·  view source on GitHub ↗

CollectDifferencesFromMaps returns a map of the differences (as slice of strings) of the values of two given maps. Map result values are added when a key is present just in one of the input maps, or if the values are different given the same key

(p1 map[string]string, p2 map[string]string)

Source from the content-addressed store, hash-verified

23// Map result values are added when a key is present just in one of the input maps, or if the values are different
24// given the same key
25func CollectDifferencesFromMaps(p1 map[string]string, p2 map[string]string) map[string][]string {
26 diff := make(map[string][]string)
27 totalKeys := make(map[string]bool)
28 for k := range p1 {
29 totalKeys[k] = true
30 }
31 for k := range p2 {
32 totalKeys[k] = true
33 }
34 for k := range totalKeys {
35 v1, ok1 := p1[k]
36 v2, ok2 := p2[k]
37 if ok1 && ok2 && v1 == v2 {
38 continue
39 }
40 diff[k] = []string{v1, v2}
41 }
42 if len(diff) > 0 {
43 return diff
44 }
45 return nil
46}
47
48// IsMapSubset returns true if mapSubset is a subset of mapSet otherwise false
49func IsMapSubset(mapSet map[string]string, mapSubset map[string]string) bool {

Callers 2

operations_test.goFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected