亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

比較2張地圖的元素-我這樣做對嗎?

比較2張地圖的元素-我這樣做對嗎?

Go
一只斗牛犬 2021-05-13 18:22:32
周末剛開始使用 Go,我不確定我是否正確使用了 Go 的特性,或者我是否根本沒有做過這種“類似 Go”的工作。該代碼應在稱為的地圖元素上進行迭代non_placed_alleles,并將每個元素與中的所有元素進行比較,這些元素placed_alleles也存儲在地圖中。我正在嘗試對每個元素使用一個go-routine,non_placed_alleles因為比較成本很高,而且要花很長時間。這是主函數的一些內容:runtime.GOMAXPROCS(8) // For 8 consecutive routines at once? got 10 CPUsc := make(chan string)for name, alleles := range non_placed_alleles {    go get_best_places(name, alleles, &placed_alleles, c)     // pointer to placed_alleles as we only read, not write - should be safe?}for channel_item := range c {    fmt.Println("This came back ", channel_item)} // This also crashes with "all goroutines are sleeping", // but all results are printed這是被調用的函數:func get_best_places(name string, alleles []string, placed_alleles *map[string] []string, c chan string) {    var best_partner string    // Iterate over all elements of placed_alleles, find best "partner"    for other_key, other_value := range *placed_alleles {        best_partner := compare_magic() // omitted because boring    }    c <- best_partner}有什么辦法可以使這個“更好”?快點?我是否正確使用了指針魔術和 goroutines?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 186 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號