On Thu, 30 Jun 2016 09:55:30 -0700 (PDT)
Chad <send2b...@gmail.com> wrote:

> I understand the worry but the more I think about it, the less I
> think it would end up being a real issue.
> 
> Taking the example of maps... two different maps that have not the
> same location in memory are never equal, especially since modifying
> one does not modify the other. It's easily explained.
> 
> For slices, explaining that it's a view of an array, and views of
> different arrays are not considered equals, it would also be easily
> explained to a beginning programmer.
> 
> Well it's merely food for thoughts. (but it would solve later issues
> in the usability of maps)

I think you can get away using helper functions.

Say, having

  type SliceKey struct {
        Ptr unitptr
  }
  
  func Key(s []byte) SliceKey
  {
    ...
  }

which would calculate whatever suits your needs from its parameter,
you could use it to actually turn your slices and maps into proper keys.

Such a function can just use package unsafe to crack the slice header
value in whatever way it wishes (as in the piece of advice from Daniel
Skinner earlier in this thread).

Working with a map would then look something like

  m := make(map[SliceKey]int)
  
  b := []byte{1, 2, 3}

  m[Key(b)] = 42
  
  v := m[Key(b)]

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to