structhash
structhash copied to clipboard
Hash does not include type name
Currently the hash only includes the fields of a struct and not the name of the struct type. This causes potentially unwanted hash collisions as seen below:
type TypeA struct {
Foo string
Bar string
}
type TypeB struct {
Foo string
Bar string
}
func TestTags(t *testing.T) {
t1 := TypeA{"foo", "bar"}
t2 := TypeB{"foo", "bar"}
h1, err := Hash(t1, 1)
if err != nil {
panic(err)
}
h2, err := Hash(t2, 1)
if err != nil {
panic(err)
}
if h1 == h2 {
t.Error("hash collision")
}
}
Thanks for the report. I don't think i'll change the current behaviour, but I might add some extra calls to give you the ability to differentiate.