是否可以使用切片作为键?
有我的尝试:
h := map[[]string]string{
[]string{"a", "b"} : "ab",
}
Run Code Online (Sandbox Code Playgroud)
编译器给我一个错误invalid map key type []string.所以要么它不可能,要么我声明错误(如果是这样,那将是一个正确的方法?).
假设我有围棋结构类型,我想作为一个地图要使用的密钥,但我不希望使用Go的内置平等的操作.建立这样一张地图的最佳方法是什么?
举一个具体的例子,这是我的键类型和相等操作:
type Key struct {
a *int
}
func Equal(x Key, y Key) bool {
return *x.a == *y.a
}
Run Code Online (Sandbox Code Playgroud)
如何构建Equal用于密钥比较的地图?
go ×2