問(wèn)題拋出
直接上代碼
package main
import (
"log"
)
func main(){
m := make(map[int]string)
m[0] = "ttttt0"
m[1] = "ttttt1"
m[2] = "ttttt2"
m[3] = "ttttt3"
m[4] = "ttttt4"
for key, value := range m{
log.Printf("k:%v,v:%v\n", key,value)
}
}
result:
從上面可以看出彼念,對(duì)于每一次遍歷結(jié)果都不相同挪圾。但是有一個(gè)規(guī)律浅萧,就是 從某個(gè)key開(kāi)始遍歷,如果結(jié)束再?gòu)念^開(kāi)始洛史,為什么會(huì)出現(xiàn)這種現(xiàn)象呢惯殊?
for range 實(shí)現(xiàn)方法
匯編命令 go tool compile -S map.go >> t.S
mapinterinit 實(shí)現(xiàn)方法: /usr/local/go/src/runtime/map.go
思路來(lái)自:EDDYCJY