3 ms·
A slice is not an array of bytes. That's exactly the point. See http://blog.golang.org/go-slices-usage-and-internals http://blog.golang.org/go-slices-usage-and
by 0x434D53 12y ago
A slice is not an array of bytes. That's exactly the point.
See http://blog.golang.org/go-slices-usage-and-internals http://blog.golang.org/go-slices-usage-and-internals
to get a basic understanding
- MichaelGG 12y agoOK so I've read it. Slices sound exactly like one would guess, using the word from other languages. A view into an array. So exactly why are they not suitable for equality? Even that article starts with "Slices are analogous to arrays in other languages". Please elaborate on this basic thing.
- 0x434D53 12y agoFor an array (which are value types in go) you have the obvious element-wise equality. For slices? Also element-wise? Even with different capacities? If the refer to the same window in the underlying array? Is there a need to copy the slice for inserting it to the map? Probably yes, because otherwise you could mutate the key from outside. But then it would be inconsistent to assignment (slices are reference types). I have no idea how this could be done concisely.
- MichaelGG 12y agoYes, element wise, why anything else? Different lengths are not equal; if capacity is externally visible, then that needs to be part of the compare. As far as the whole ownership issue, that's a bit more than just ==, isn't it? Equality was the only thing I was questioning.