petar/GoLLRB — Issue #4: serializing llrb with gob causes a runtime error: invalid memory address
Author: senior7515
Created: 2011-12-12 03:55:38+00:00
State: open

Hi Petar,

Thanks for writing this data structure.

I was giving it a drive, and the following throws a runtime panic

func lessString(a, b interface{}) bool {
return a.(string) < b.(string)
}

iofile, err := os.OpenFile("testfile.gob", os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
panic("Could not find, or create file: error code:" + err.String())
}
enc := gob.NewEncoder(iofile)
//dec := gob.NewDecoder(iofile)

tree := llrb.New(lessString)
tree.ReplaceOrInsert("alex")
errdecode := enc.Encode(tree)
if errdecode != nil {
fmt.Printf("decode error:%s", err.String())
}
return nil

However, if you simply encode another struct like this one

type Test struct {

}