package main
import (
"fmt"
"sync"
)
type Key struct {
A int64
B int64
}
func main() {
timers := new(sync.Map)
timers.Store(&Key{
A: 10,
B: 2,
}, "test1")
if a, ok := timers.Load(&Key{
A: 10,
B: 2,
}); ok {
v := a.(string)
fmt.Println(v)
}
}
运行未打印出"test1"
Process finished with the exit code 0
运行如下代码:
package main
import (
"fmt"
"sync"
)
type Key struct {
A int64
B int64
}
func main() {
timers := new(sync.Map)
timers.Store(Key{
A: 10,
B: 2,
}, "test1")
if a, ok := timers.Load(Key{
A: 10,
B: 2,
}); ok {
v := a.(string)
fmt.Println(v)
}
}
结果:
test1
Process finished with the exit code 0
此哈希表并没有提供对应的哈希函数和比较函数,不太好用。