AddChild() public method

public AddChild ( DawgNode node ) : bool
node DawgNode
return bool
Example #1
0
        public Dawg Decode(Stream stream)
        {
            using (var reader = new BinaryReader(stream))
            {
                var fileVersion = reader.ReadSingle();
                if (_version != fileVersion)
                {
                    throw new ApplicationException(string.Format("The file version of dawg is not match.\rThe decoder version is {0},but file version is {1}", _version, fileVersion));
                }
                var allNodes = new DawgNode[reader.ReadInt32()];
                //read header of dawg file
                for (var i = 0; i < allNodes.Length; i++)
                {
                    var text  = (char)reader.ReadInt16();
                    var freq  = reader.ReadInt32();
                    var depth = reader.ReadInt32();
                    var eow   = reader.ReadBoolean();
                    var size  = reader.ReadInt32();
                    var node  = new DawgNode(text, size);
                    node.Eow       = eow;
                    node.Depth     = depth;
                    node.Frequency = freq;
                    allNodes[i]    = node;
                }
                //build a dawg.

                var count = reader.ReadInt32();
                var root  = new DawgNode(new char(), count);
                for (var i = 0; i < count; i++)
                {
                    var node = allNodes[reader.ReadInt32()];
                    root.AddChild(node);
                }
                count = reader.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    var label          = reader.ReadInt32();
                    var node           = allNodes[label];
                    var childNodeCount = reader.ReadInt32();
                    for (var j = 0; j < childNodeCount; j++)
                    {
                        var childNode = allNodes[reader.ReadInt32()];
                        node.AddChild(childNode);
                    }
                }
                return(new Dawg(root));
            }
        }
Example #2
0
        public Dawg Decode(Stream stream)
        {
            using (var reader = new BinaryReader(stream))
            {
                var fileVersion = reader.ReadDouble();
                if (_version != fileVersion)
                {
                    throw new ApplicationException(string.Format("The file version of dawg is not match.\rThe decoder version is {0},but file version is {1}", _version, fileVersion));
                }
                var allNodes = new DawgNode[reader.ReadInt32()];
                //read header of dawg file
                for (var i = 0; i < allNodes.Length; i++)
                {
                    var text = (char)reader.ReadInt16();
                    var freq = reader.ReadInt32();
                    var depth = reader.ReadInt32();
                    var eow = reader.ReadBoolean();
                    var size = reader.ReadInt32();
                    var node = new DawgNode(text, size);
                    node.Eow = eow;
                    node.Depth = depth;
                    node.Frequency = freq;
                    allNodes[i] = node;
                }
                //build a dawg.

                var count = reader.ReadInt32();
                var root = new DawgNode(new char(), count);
                for (var i = 0; i < count; i++)
                {
                    var node = allNodes[reader.ReadInt32()];
                    root.AddChild(node);
                }
                count = reader.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    var label = reader.ReadInt32();
                    var node = allNodes[label];
                    var childNodeCount = reader.ReadInt32();
                    for (var j = 0; j < childNodeCount; j++)
                    {
                        var childNode = allNodes[reader.ReadInt32()];
                        node.AddChild(childNode);
                    }
                }
                return new Dawg(root);
            }
        }