2 回答
TA贡献1828条经验 获得超4个赞
您需要再次将数组分配给映射。
nbrs0 := n.rebuilt[4] nbrs1 := n.rebuilt[0] nbrs0[2] = 0 nbrs1[1] = 4 n.rebuilt[4] = nrbs0 n.rebuilt[0] = nrbs1
当您分配给 您时,请制作原始数组的副本。因此,更改不会传播到 map,您需要使用新数组显式更新映射。nbrsN
TA贡献1829条经验 获得超6个赞
您需要将值重新分配给地图条目...
package main
import (
"fmt"
"math"
)
type Neighborhood struct {
rebuilt map[uint32][3]uint32 // Facet index vs {neighbor0, neighbor1, neighbor2}
}
func main() {
n := &Neighborhood{
rebuilt: make(map[uint32][3]uint32, 9348),
}
// Populate neighbors with default of UINT32_MAX
for i := uint32(0); i < 3; i++ {
n.rebuilt[i] = [3]uint32{math.MaxUint32, math.MaxUint32, math.MaxUint32}
}
v := n.rebuilt[1]
v[1] = uint32(0)
fmt.Printf("%v\n", v)
fmt.Printf("%v\n", n)
n.rebuilt[1] = v
fmt.Printf("%v\n", n)
}
https://play.golang.org/p/Hk5PRZlHUYc
- 2 回答
- 0 关注
- 139 浏览
添加回答
举报
