Thanks Jason, I get your point about DeepEqual now :) On Tuesday, 18 July 2023 at 16:52:51 UTC+1 Jason Phillips wrote:
> Also note: reflect.DeepEqual doesn't *just* compare the contents of the > map. It only compares contents if the maps aren't "the same map object". > From the documentation: > > > Map values are deeply equal when all of the following are true: they are > both nil or both non-nil, they have the same length, and either they are > the same map object or their corresponding keys (matched using Go equality) > map to deeply equal values. > > Comparing if they're "the same map object" is done in the way described > earlier, which seems exactly what you're looking for. > > On Tuesday, July 18, 2023 at 11:44:53 AM UTC-4 Jason Phillips wrote: > >> reflect.Value.UnsafePointer() is probably not safer than using unsafe >> directly, assuming you're using unsafe in a way that doesn't break the >> rules. Reflect is doing effectively the same unsafe.Pointer conversion >> under the hood [1]. It's certainly easier on the eyes, in my opinion, >> though. >> >> [1] - >> https://cs.opensource.google/go/go/+/refs/tags/go1.20.6:src/reflect/value.go;l=103 >> >> On Tuesday, July 18, 2023 at 11:25:42 AM UTC-4 Stephen Illingworth wrote: >> >>> >>> I like that. I think it's is quite a smart way of doing it, >>> >>> I don't think you need to check both maps when choosing a key. Once >>> you've found a candidate key in one map, you can test the other map and if >>> it *does* exist then the two maps aren't equal. You've then saved the >>> insertion and deletion step. I would also prefer to use rand.Int() rather >>> than a linear search. >>> >>> https://go.dev/play/p/ftBGgQMuvvC >>> >>> >>> On Tuesday, 18 July 2023 at 15:35:38 UTC+1 Jochen Voss wrote: >>> >>>> Dear all, >>>> >>>> To implement the "eq" operator in a simple PostScript interpreter, I >>>> need to determine whether two maps are the same object. >>>> >>>> This can be done by adding a new element to one map, and checking >>>> whether the new entry also appears in the second map, but as you can >>>> imagine, the resulting code is quite ugly. See >>>> https://go.dev/play/p/AfembYDt3en for an implementation of this idea. >>>> >>>> Is there a better way? >>>> >>>> Many thanks, >>>> Jochen >>>> >>>> -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c8b9aac5-6a53-472f-9c5d-497a23575a79n%40googlegroups.com.