IMO the following *should* print true, but doesn't:
a1 := "arst"
a2 := "arst"
a3 := map[*string]bool{&a1: true}
a4 := map[*string]bool{&a2: true}
fmt.Println(reflect.DeepEqual(a3, a4))
For reference/sanity checking, these two both do match:
a5 := map[string]bool{a1: true}
a6 := map[string]bool{a2: true}
fmt.Println(reflect.DeepEqual(a5, a6))
a7 := map[int]*string{55: &a1}
a8 := map[int]*string{55: &a2}
fmt.Println(reflect.DeepEqual(a7, a8))
http://play.golang.org/p/jLTaCRTedt
Should DeepEqual be inspecting the types of map keys and dereferencing them
if they are pointers? It dereferences all other instances of pointers that
it encounters, so I would claim: yes.
Background: I'm building some large data structures out of text, and I'm
trying to avoid creating tens or hundreds of copies of each string, yet
still maintain many references to them to optimize the way I access them.
This approach works fine in code, but when writing tests, I ran into
trouble, because I am trying to test by building two versions of my data
structure and comparing them with a DeepEqual. This doesn't work because
they end up with different pointers as their keys, even though the values
of those pointers match.
Thanks,
Doug
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.