changed the title runtime/build: panic: runtime error: hash of unhashable type [2]string runtime: panic: runtime error: hash of unhashable type [2]string on May 24, 2024 ianlancetayloradded compiler/runtimeIssues related to the Go compiler and/or runtime. on May 24, 2024 titpetric ...
go run main.go panic: runtime error: hash of unhashable type []int goroutine 1 [running]: main.main() /Users/frank/Desktop/go-concurrent/lesson09/map-key/main.go:8 +0x145 exit status 2 阅读上面的代码,我们将slice作为interface{}的值,用作 map 的 key,golang 编译器并没有提示错误,但是...
panic: runtime error: hash of unhashable type [4]int32 goroutine 1 [running]: main.main() /tmp/sandbox3460698193/prog.go:15 +0xc7 What did you expect to see? no panic gopherbotadded thecompiler/runtimeIssues related to the Go compiler and/or runtime.labelFeb 27, 2024 ...
//panic: runtime error: hash of unhashable type []int println(m[i]) //panic: runtime error: hash of unhashable type []int delete(m, i) 为什么不可以用[]int作为 key 呢? 查找源码中 hash 的调用链注释如下: // runtime/map.go // mapassign,mapaccess1 中 获取 key 的 hash hash := ...
go run main.gopanic:runtime error:hashofunhashable type[]int goroutine1[running]:main.main()/Users/frank/Desktop/go-concurrent/lesson09/map-key/main.go:8+0x145exit status2 阅读上面的代码,我们将slice作为interface{}的值,用作 map 的 key,golang编译器并没有提示错误,但是在运行时引发 panic。我...
logger.Infof("mp: %+v", mp) } Results: panic: runtimeerror: hash of unhashabletypemap[int]int[2020-03-3015:06:32] INFO mp:map[{Y:[123]}:256] goroutine1[running]: main.main() /Users/torapture/Codes/repos/go/src/go-learn/main.go:33+0x1a2...
map 又称为 hash map,在算法上基于 hash 实现 key 的映射和寻址;在数据结构上基于桶数组实现 key-...
array是可hash的,而slice不是,因为slice的底层ArrayPtr是可变的,【这似乎是为什么一定要使用array而不是slice的唯一场景,参考资料详见:https://www.reddit.com/r/golang/comments/ecqgha/why_are_slices_in_go_unhashable/,https://stackoverflow.com/questions/30694652/why-use-arrays-instead-of-slices】 ...
A nitpick perhaps, but go already has a comparable collection type, namely, the array. What I do is then the old, old trick of using an array that is "big enough" for my purposes, and then I use it as a hash map key. See here on how I use this in one of my projects: https...
const bucketCnt = 8 type bmap struct { tophash [bucketCnt]uint8 } (1)bmap 就是 map 中的桶,可以存储 8 组 key-value 对的数据,以及一个指向下一个溢出桶的指针; (2)每组 key-value 对数据包含 key 高 8 位 hash 值 tophash,key 和 val 三部分; (3)在代码层面只展示了 tophash 部分,但由...