コード例 #1
0
    public void TestNonEmptyNodeFixedSize()
    {
        var nodeManager = new TreeDiskNodeManager <int, long> (
            new TreeIntSerializer(),
            new TreeLongSerializer(),
            new RecordStorage(new BlockStorage(new MemoryStream(), 4096, 48))
            );
        var node = new TreeNode <int, long> (nodeManager, 11, 88, new List <Tuple <int, long> > {
            new Tuple <int, long>(11, 22L),
            new Tuple <int, long>(22, 33L),
            new Tuple <int, long>(44, 55L)
        }, new List <uint> {
            111, 222, 333, 444, 555
        });
        var serializer = new TreeDiskNodeSerializer <int, long> (nodeManager, new TreeIntSerializer(), new TreeLongSerializer());

        var data = serializer.Serialize(node);

        var node2 = serializer.Deserialize(11, data);

        Assert.NotNull(node2);
        Assert.AreEqual(node.Id, node2.Id);
        Assert.AreEqual(node.ParentId, node2.ParentId);
        Assert.IsTrue(node.Entries.SequenceEqual(node2.Entries));
        Assert.IsTrue(node.ChildrenIds.SequenceEqual(node2.ChildrenIds));
    }
コード例 #2
0
    public void TestVariableLengthKeySize()
    {
        var nodeManager = new TreeDiskNodeManager <string, long> (
            new TreeStringSerialzier(),
            new TreeLongSerializer(),
            new RecordStorage(new BlockStorage(new MemoryStream(), 4096, 48))
            );
        var node = new TreeNode <string, long> (nodeManager, 11, 88, new List <Tuple <string, long> > {
            new Tuple <string, long>("The quick brown foxs run over the lazy dog", 22L),
            new Tuple <string, long>("I dont really understand what i am doing", 33L),
            new Tuple <string, long>(String.Empty, 55L)
        }, new List <uint> {
            111, 222, 333, 444, 555
        });
        var serializer = new TreeDiskNodeSerializer <string, long> (nodeManager, new TreeStringSerialzier(), new TreeLongSerializer());

        var data = serializer.Serialize(node);

        var node2 = serializer.Deserialize(11, data);

        Assert.NotNull(node2);
        Assert.AreEqual(node.Id, node2.Id);
        Assert.AreEqual(node.ParentId, node2.ParentId);
        Assert.IsTrue(node.Entries.SequenceEqual(node2.Entries));
        Assert.IsTrue(node.ChildrenIds.SequenceEqual(node2.ChildrenIds));
    }
コード例 #3
0
	public void TestNonEmptyNodeFixedSize ()
	{
		var nodeManager = new TreeDiskNodeManager<int, long> (
			new TreeIntSerializer (), 
			new TreeLongSerializer(),
			new RecordStorage (new BlockStorage(new MemoryStream(), 4096, 48))
		);
		var node = new TreeNode<int, long> (nodeManager, 11, 88, new List<Tuple<int, long>> {
			new Tuple<int, long>(11, 22L),
			new Tuple<int, long>(22, 33L),
			new Tuple<int, long>(44, 55L)
		}, new List<uint> {
			111,222,333,444,555
		});
		var serializer = new TreeDiskNodeSerializer<int, long> (nodeManager, new TreeIntSerializer(), new TreeLongSerializer());

		var data = serializer.Serialize (node);

		var node2 = serializer.Deserialize (11, data);

		Assert.NotNull (node2);
		Assert.AreEqual (node.Id, node2.Id);
		Assert.AreEqual (node.ParentId, node2.ParentId);
		Assert.IsTrue (node.Entries.SequenceEqual(node2.Entries));
		Assert.IsTrue (node.ChildrenIds.SequenceEqual(node2.ChildrenIds));
	}
コード例 #4
0
	public void TestVariableLengthKeySize ()
	{
		var nodeManager = new TreeDiskNodeManager<string, long> (
			new TreeStringSerialzier (), 
			new TreeLongSerializer(),
			new RecordStorage (new BlockStorage(new MemoryStream(), 4096, 48))
		);
		var node = new TreeNode<string, long> (nodeManager, 11, 88, new List<Tuple<string, long>> {
			new Tuple<string, long>("The quick brown foxs run over the lazy dog", 22L),
			new Tuple<string, long>("I dont really understand what i am doing", 33L),
			new Tuple<string, long>(String.Empty, 55L)
		}, new List<uint> {
			111, 222, 333, 444, 555
		});
		var serializer = new TreeDiskNodeSerializer<string, long> (nodeManager, new TreeStringSerialzier(), new TreeLongSerializer());

		var data = serializer.Serialize (node);

		var node2 = serializer.Deserialize (11, data);

		Assert.NotNull (node2);
		Assert.AreEqual (node.Id, node2.Id);
		Assert.AreEqual (node.ParentId, node2.ParentId);
		Assert.IsTrue (node.Entries.SequenceEqual(node2.Entries));
		Assert.IsTrue (node.ChildrenIds.SequenceEqual(node2.ChildrenIds));
	}
コード例 #5
0
    public void TestEmptyNodeFixedSize()
    {
        var nodeManager = new TreeDiskNodeManager <int, long> (
            new TreeIntSerializer(),
            new TreeLongSerializer(),
            new RecordStorage(new BlockStorage(new MemoryStream(), 4096, 48))
            );
        var node       = new TreeNode <int, long> (nodeManager, 11, 88);
        var serializer = new TreeDiskNodeSerializer <int, long> (nodeManager, new TreeIntSerializer(), new TreeLongSerializer());

        var data = serializer.Serialize(node);

        var node2 = serializer.Deserialize(11, data);

        Assert.NotNull(node2);
        Assert.AreEqual(node.Id, node2.Id);
        Assert.AreEqual(node.ParentId, node2.ParentId);
        Assert.IsTrue(node.Entries.SequenceEqual(node2.Entries));
        Assert.IsTrue(node.ChildrenIds.SequenceEqual(node2.ChildrenIds));
    }
コード例 #6
0
	public void TestEmptyNodeFixedSize ()
	{
		var nodeManager = new TreeDiskNodeManager<int, long> (
			new TreeIntSerializer (),
			new TreeLongSerializer(),
			new RecordStorage (new BlockStorage(new MemoryStream(), 4096, 48))
		);
		var node = new TreeNode<int, long> (nodeManager, 11, 88);
		var serializer = new TreeDiskNodeSerializer<int, long> (nodeManager, new TreeIntSerializer(), new TreeLongSerializer());

		var data = serializer.Serialize (node);

		var node2 = serializer.Deserialize (11, data);

		Assert.NotNull (node2);
		Assert.AreEqual (node.Id, node2.Id);
		Assert.AreEqual (node.ParentId, node2.ParentId);
		Assert.IsTrue (node.Entries.SequenceEqual(node2.Entries));
		Assert.IsTrue (node.ChildrenIds.SequenceEqual(node2.ChildrenIds));
	}
コード例 #7
0
        public void TestSavingEmptyTree()
        {
            // Create a tree with random elements,
            // presist it in a memory stream and then reconstruct it
            // BasicConfigurator.Configure ();

            var stream = new MemoryStream();

            // Create the first tree
            var nodeManager = new TreeDiskNodeManager <int, long>(
                new TreeIntSerializer(),
                new TreeLongSerializer(),
                new RecordStorage(
                    new BlockStorage(
                        stream,
                        4096,
                        48
                        )
                    )
                );
            var tree = new Tree <int, long>(nodeManager);

            // Init new tree
            stream.Position = 0;
            var nodeManager2 = new TreeDiskNodeManager <int, long>(
                new TreeIntSerializer(),
                new TreeLongSerializer(),
                new RecordStorage(
                    new BlockStorage(
                        stream,
                        4096,
                        48
                        )
                    )
                );
            var tree2  = new Tree <int, long>(nodeManager2);
            var result = (from i in tree2.LargerThanOrEqualTo(0) select i).ToList();

            Assert.IsEmpty(result);
        }
コード例 #8
0
ファイル: PersistentTreeTest.cs プロジェクト: K-Eo/FooDB
		public void TestSavingEmptyTree ()
		{
			// Create a tree with random elements,
			// presist it in a memory stream and then reconstruct it
			BasicConfigurator.Configure ();

			var stream = new MemoryStream ();

			// Create the first tree
			var nodeManager = new TreeDiskNodeManager<int, long> (
				new TreeIntSerializer(),
				new TreeLongSerializer(),
				new RecordStorage(
					new BlockStorage(
						stream, 
						4096, 
						48
					)
				)
			); 
			var tree = new Tree<int, long>(nodeManager);

			// Init new tree
			stream.Position = 0;
			var nodeManager2 = new TreeDiskNodeManager<int, long> (
				new TreeIntSerializer(),
				new TreeLongSerializer(),
				new RecordStorage(
					new BlockStorage(
						stream, 
						4096, 
						48
					)
				)
			); 
			var tree2 = new Tree<int, long>(nodeManager2);
			var result = (from i in tree2.LargerThanOrEqualTo (0) select i).ToList();
			Assert.IsEmpty (result);
		}