Exemplo n.º 1
0
        private static void TestBTree()
        {
            var tree = new BTree(3);

            for (var i = 0; i < 8; i++)
            {
                tree.Insert((ulong)i, (ulong)(i + 10));

                for (var j = 0; j <= i; j++)
                {
                    Debug.Assert(tree.Find((ulong)j).SequenceEqual(new[] { (ulong)(j + 10) }));
                }
            }

            using (var file = File.OpenWrite("treetest.bin"))
            {
                tree.Write(new BinaryWriter(file));
            }

            var newTree = new BTree(3);

            using (var file = File.OpenRead("treetest.bin"))
            {
                newTree.Read(new BinaryReader(file));
            }

            for (var i = 0; i < 8; i++)
            {
                Debug.Assert(tree.Find((ulong)i).SequenceEqual(new[] { (ulong)(i + 10) }));
            }
        }
Exemplo n.º 2
0
        public JbtReader(EndianBinaryReader reader)
        {
            if (reader.BaseStream.CanSeek)
            {
                this.reader = reader;
            }
            else
            {
                memoryStream = new MemoryStream();

                memoryStream.Write(reader.ReadBytes((int)reader.BaseStream.Length), 0, (int)reader.BaseStream.Length);

                this.reader = new EndianBinaryReader(reader.BitConverter, memoryStream);
            }

            var pos = reader.ReadInt64();

            reader.Seek((int)pos, SeekOrigin.Begin);

            tree = new BTree();
            tree.Read(new BinaryReader(reader.BaseStream));
        }
Exemplo n.º 3
0
        public JbtWriter(EndianBinaryWriter writer)
        {
            if (writer.BaseStream.CanSeek)
            {
                usingWrapper = false;

                this.writer = writer;
            }
            else
            {
                usingWrapper = true;
                wrappedWriter = writer;
                memoryStream = new MemoryStream();

                this.writer = new EndianBinaryWriter(writer.BitConverter, memoryStream);
            }

            // Placeholder for pointer
            this.writer.Write((long)0);

            tree = new BTree();
        }