我得到一个ProtoException("可能的递归检测到(偏移:4级):o EOW")序列化树结构时如下:
var tree = new PrefixTree();
tree.Add("racket".ToCharArray());
tree.Add("rambo".ToCharArray());
using (var stream = File.Open("test.prefix", FileMode.Create))
{
Serializer.Serialize(stream, tree);
}
Run Code Online (Sandbox Code Playgroud)
树实现:
[ProtoContract]
public class PrefixTree
{
public PrefixTree()
{
_nodes = new Dictionary<char, PrefixTree>();
}
public PrefixTree(char[] chars, PrefixTree parent)
{
if (chars == null) throw new ArgumentNullException("chars");
if (parent == null) throw new ArgumentNullException("parent");
if (chars.Length == 0) throw new ArgumentException();
_parent = parent;
_nodes = new Dictionary<char, PrefixTree>();
_value = chars[0];
var overflow = chars.SubSet(1);
if (!overflow.Any()) …Run Code Online (Sandbox Code Playgroud)