Last active
August 29, 2015 14:07
-
-
Save darthberen/55ec88128e89cfa4e185 to your computer and use it in GitHub Desktop.
go map comparison code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
map1 := make(map[string]string) | |
map2 := make(map[string]string) | |
var mapNil map[string]string | |
mapNil = nil | |
fmt.Println("map1:", map1) | |
fmt.Println("map2:", map2) | |
fmt.Println("mapNil:", mapNil) | |
fmt.Println("Length of map1:", len(map1)) | |
fmt.Println("Length of map2:", len(map2)) | |
fmt.Println("Length of mapNil:", len(mapNil)) | |
fmt.Println("1) map1 == map2:", reflect.DeepEqual(map1, map2)) | |
fmt.Println("2) map1 == mapNil:", reflect.DeepEqual(map1, mapNil)) | |
fmt.Println("3) map1 == mapNil || len(map1) == len(mapNil):", (len(map1) == 0 && len(mapNil) == 0) || reflect.DeepEqual(map1, mapNil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment