Hi
For a custom project, I'm trying to write a serializer for a trie
datastructure. I was using gob but it is slow due to it's use of
reflect, and I wanted to learn something new.
The struct is mainly composed of nodes:
// Node implements a node of the tree
type Node struct {
// rw is a RWMutex, can be hold by either
// 1 writer or many reader
rw sync.RWMutex
// Sons and Radix holds information about the "descendant" of this node
Sons []*Node
Radix []string
// Refs hold information about the word ending at this node
Refs []Ref
}
The refs slice is data about the node itself (my trie is used as an
index). Basically a list of id and a list of float64.
Sons is a slice of pointer to other nodes, and Radix is a slice of
strings which are the radix matching each of the sons, both slice have
the same length.
The code relevant to the serialization is here
https://github.com/Succo/rechercheInfoWeb/blob/customSerializer/encoder.go
I'm trying to encode the trie recursively. For each node I first encode
the refs slice length, then all the int in order, and then all floats in
order. Then I encode the length of the string slice, and then each
string in order, by first writing the string length, and then
[]byte(str). I finish by recursively encoding all nodes in the Sons slice.
When I try to decode the encoded file, it crashes at some point (always
the same) because one of the length is absurdly high (either the slice
of string itself or one of the string). Which I suppose mean it's
reading data corresponding to something else. until this point all read
data seems consistent as far as I could see.
I have helper function to encode and decode int, floats and []string,
all seem to pass basic test. I tried to use a smaller trie and it was
successfully encoded and decoded. If I remove the part about encoding
and decoding the slice of string it works, but obviously it's missing data.
I really have no idea what causes the corrupted, I imagine it's because
at some point some data don't get committed but I can't see why.
Can anybody help me with this?
Thank you
Fabrice
--
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.