gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/def/map.go (about) 1 package def 2 3 func MakeMap[K comparable, V any](m map[K]V) map[K]V { 4 if m == nil { 5 return make(map[K]V) 6 } 7 return m 8 } 9 10 func MakeSizeMap[K comparable, V any](m map[K]V, size int) map[K]V { 11 if m == nil { 12 return make(map[K]V, size) 13 } 14 return m 15 } 16 17 func SetMap[K comparable, V any](m map[K]V, def map[K]V) map[K]V { 18 if m == nil { 19 return def 20 } 21 return m 22 } 23 24 func SetterMap[K comparable, V any](m map[K]V, setter func() map[K]V) map[K]V { 25 if m == nil { 26 return setter() 27 } 28 return m 29 } 30 31 func MakeMapP[K comparable, V any](mp *map[K]V) { 32 if *mp == nil { 33 *mp = make(map[K]V) 34 } 35 } 36 37 func MakeSizeMapP[K comparable, V any](mp *map[K]V, size int) { 38 if *mp == nil { 39 *mp = make(map[K]V, size) 40 } 41 } 42 43 func SetMapP[K comparable, V any](mp *map[K]V, def map[K]V) { 44 if *mp == nil { 45 *mp = def 46 } 47 } 48 49 func SetterMapP[K comparable, V any](mp *map[K]V, setter func() map[K]V) { 50 if *mp == nil { 51 *mp = setter() 52 } 53 }