Example #1
0
        public void Can_get_weight()
        {
            var tree = new LcrsTrie('\0', false);

            tree.Add("pap");
            tree.Add("papp");
            tree.Add("papaya");

            Assert.AreEqual(8, tree.GetWeight());

            tree.Add("ape");
            tree.Add("apelsin");

            Assert.AreEqual(15, tree.GetWeight());
        }
Example #2
0
        private static void SerializeMappedDepthFirst(this LcrsTrie node, Stream stream, int depth)
        {
            var bytes = TypeToBytes(new LcrsNode(node, depth, node.GetWeight()));

            stream.Write(bytes, 0, bytes.Length);

            if (node.LeftChild != null)
            {
                node.LeftChild.SerializeMappedDepthFirst(stream, depth + 1);
            }

            if (node.RightSibling != null)
            {
                node.RightSibling.SerializeMappedDepthFirst(stream, depth);
            }
        }