I am familiar with the way to check if a key already exists in a map, such as:
m := make(map[int]int)
m[1] = 2
val, ok := m[1] // gives 2, true
val, ok := m[2] // gives 0, false
I can use a similar expression for a map of maps and it seems to compile and give the correct result:
m := make(map[int]map[int]string)
if val, ok := m[0][0]; ok {
fmt.Println("key exists, corresponding value: ", val) // does not print
}
Is this the proper way to implement 2d maps if what I mainly want is to quickly check for the existence of a given 2d key (basically, an xy grid point as a key). Or would it be better to use a 1d map with a hash function, or even struct and iterate through the map checking for equality of keys?