轉到符合規範states:如何在Go中創建一個map [[16] byte] []字符串?
The comparison operators == and != (§Comparison operators) must be fully defined for operands of the key type; thus the key type must not be a struct, array or slice. If the key type is an interface type, these comparison operators must be defined for the dynamic key values; failure will cause a run-time panic.
我想創建地圖的散列值,其來自Hash界面,返回[]byte
,但其中我所有的哈希值與相同的算法做(這樣,我知道它適合於[16]byte
)。我怎樣才能提供適當的接口,使得map
類型將允許[]byte
或[16]byte
或其某些包裝被用作密鑰?
目前我使用生成以下錯誤:
dupes := make(map[[16]byte][]string)
finddups.go:55: invalid map key type [16]uint8
更新(2012年3月): GO1允許[16]byte
爲重點類型。
你能解釋爲什麼會出現這種情況嗎?轉換爲可接受的魔術類型似乎是任意的。 – 2010-11-26 17:09:10