当前位置: 首页>>代码示例>>C#>>正文


C# Tree.LargerThanOrEqualTo方法代码示例

本文整理汇总了C#中Tree.LargerThanOrEqualTo方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.LargerThanOrEqualTo方法的具体用法?C# Tree.LargerThanOrEqualTo怎么用?C# Tree.LargerThanOrEqualTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tree的用法示例。


在下文中一共展示了Tree.LargerThanOrEqualTo方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NonFullRootNodeTest

		public void NonFullRootNodeTest ()
		{
			var tree = new Tree<int, string>(new TreeMemoryNodeManager<int, string>(2, Comparer<int>.Default));

			tree.Insert (1, "1");

			Assert.AreEqual (0, (from node in tree.LargerThan(7) select node).Count());
			Assert.AreEqual (0, (from node in tree.LargerThanOrEqualTo(7) select node).Count());
			Assert.AreEqual (1, (from node in tree.LessThan(7) select node).FirstOrDefault().Item1);
			Assert.AreEqual (1, (from node in tree.LessThanOrEqualTo(7) select node).FirstOrDefault().Item1);
			Assert.AreEqual (1, (from node in tree.LessThanOrEqualTo(1) select node).FirstOrDefault().Item1);
			Assert.AreEqual (0, (from node in tree.LessThan(1) select node).Count());

			tree.Insert (5, "2");
			tree.Insert (9, "9");

			// 1,5,9

			Assert.IsTrue ((from node in tree.LessThanOrEqualTo(9) select node.Item1).SequenceEqual(new int[] { 9, 5, 1 }));
			Assert.IsTrue ((from node in tree.LessThan(9) select node.Item1).SequenceEqual(new int[] { 5, 1 }));
			Assert.IsTrue ((from node in tree.LargerThanOrEqualTo(5) select node.Item1).SequenceEqual(new int[] { 5, 9 }));
			Assert.IsTrue ((from node in tree.LargerThan(5) select node.Item1).SequenceEqual(new int[] { 9 }));


			Assert.Throws<TreeKeyExistsException>(delegate {
				tree.Insert (9, "9");
			});
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:28,代码来源:BTreeTest.cs

示例2: NonFullRootNodeTest

		public void NonFullRootNodeTest ()
		{
			var tree = new Tree<int, string>(new TreeMemoryNodeManager<int, string>(2, Comparer<int>.Default),
				allowDuplicateKeys: true);

			tree.Insert (1, "1");

			Assert.AreEqual (0, (from node in tree.LargerThan(7) select node).Count());
			Assert.AreEqual (0, (from node in tree.LargerThanOrEqualTo(7) select node).Count());
			Assert.AreEqual (1, (from node in tree.LessThan(7) select node).FirstOrDefault().Item1);
			Assert.AreEqual (1, (from node in tree.LessThanOrEqualTo(7) select node).FirstOrDefault().Item1);
			Assert.AreEqual (1, (from node in tree.LessThanOrEqualTo(1) select node).FirstOrDefault().Item1);
			Assert.AreEqual (0, (from node in tree.LessThan(1) select node).Count());

			tree.Insert (5, "5");
			tree.Insert (9, "9");

			// 1,5,9

			Assert.IsTrue ((from node in tree.LessThanOrEqualTo(9) select node.Item1).SequenceEqual(new int[] { 9, 5, 1 }));
			Assert.IsTrue ((from node in tree.LessThan(9) select node.Item1).SequenceEqual(new int[] { 5, 1 }));
			Assert.IsTrue ((from node in tree.LargerThanOrEqualTo(5) select node.Item1).SequenceEqual(new int[] { 5, 9 }));
			Assert.IsTrue ((from node in tree.LargerThan(5) select node.Item1).SequenceEqual(new int[] { 9 }));


			Assert.DoesNotThrow(delegate {
				tree.Insert (5, "5.1");
			});

			// Iterating test
			var found = (from node in tree.LargerThanOrEqualTo(5) select node.Item2).ToList ();
			Assert.AreEqual (3, found.Count);
			Assert.IsTrue (found.Contains("5.1"));
			Assert.IsTrue (found.Contains("5"));
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:35,代码来源:BTreeNonUniqueTest.cs

示例3: UniqueTreeTest

		public void UniqueTreeTest ()
		{
			// Unique tree
			var expectedRemain = new List<double>();
			var tree = new Tree<double, string>(
				new TreeMemoryNodeManager<double, string>(2, Comparer<double>.Default)
			);

			// Insert random numbers
			for (var i = 0; i < 1000; i++) {
				tree.Insert (i, i.ToString());
				expectedRemain.Add (i);
			}

			// Start deleting randomly
			var rnd = new Random ();
			for (var i = 0; i < 1000; i++) {
				var deleteAt = rnd.Next (0, expectedRemain.Count);
				var keyToDelete = expectedRemain[deleteAt];
				expectedRemain.RemoveAt (deleteAt);
				tree.Delete (keyToDelete);
				var remain = (from entry in tree.LargerThanOrEqualTo(0) select entry.Item1).ToArray();
				Assert.IsTrue (remain.SequenceEqual (expectedRemain));
			}

			Assert.Throws<InvalidOperationException>(delegate {
				tree.Delete (888, "888");
			});
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:29,代码来源:BTreeDeletionTest.cs

示例4: SplitRootNodeTest

		public void SplitRootNodeTest ()
		{
			// Insert too much at root node that it overvlow
			var tree = new Tree<int, string>(new TreeMemoryNodeManager<int, string>(2, Comparer<int>.Default));

			tree.Insert (0, "00");
			tree.Insert (1, "11");
			tree.Insert (2, "22");
			tree.Insert (3, "33");
			tree.Insert (4, "44");

			// Validate the tree
			Assert.IsNull (tree.Get(8));
			Assert.IsNull (tree.Get(-1));
			Assert.IsNull (tree.Get(99));

			Assert.NotNull (tree.Get (0));
			Assert.NotNull (tree.Get (1));
			Assert.NotNull (tree.Get (2));
			Assert.NotNull (tree.Get (3));
			Assert.NotNull (tree.Get (4));

			Assert.IsTrue ((from tpl in tree.LargerThanOrEqualTo(4) select tpl.Item1).SequenceEqual(new int[]{ 4 }));
			Assert.IsTrue ((from tpl in tree.LargerThan(1) select tpl.Item1).SequenceEqual(new int[]{ 2, 3, 4 }));
			Assert.IsTrue ((from tpl in tree.LessThan(3) select tpl.Item1).SequenceEqual(new int[]{ 2,1,0 }));
			Assert.IsTrue ((from tpl in tree.LessThanOrEqualTo(3) select tpl.Item1).SequenceEqual(new int[]{ 3, 2,1,0 }));
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:27,代码来源:BTreeTest.cs

示例5: EmptyTreeTest

		public void EmptyTreeTest ()
		{
			var tree = new Tree<int, string>(new TreeMemoryNodeManager<int, string>(2, Comparer<int>.Default));

			Assert.AreEqual (0, (from node in tree.LargerThan(7) select node).Count());
			Assert.AreEqual (0, (from node in tree.LargerThanOrEqualTo(7) select node).Count());
			Assert.AreEqual (0, (from node in tree.LessThan(7) select node).Count());
			Assert.AreEqual (0, (from node in tree.LessThanOrEqualTo(7) select node).Count());

		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:10,代码来源:BTreeTest.cs

示例6: NonFullRootNodeTest

		public void NonFullRootNodeTest ()
		{
			// Unique tree
			var tree = new Tree<double, string>(
				new TreeMemoryNodeManager<double, string>(2, Comparer<double>.Default)
			);

			tree.Insert (1, "1");
			tree.Insert (3, "3");
			tree.Insert (6, "6");
			tree.Insert (8, "8");

			tree.Delete (6);
			Assert.IsTrue ((from t in tree.LargerThanOrEqualTo(0) select t.Item1).SequenceEqual(new double[] { 1, 3, 8 }));

			tree.Delete (3);
			Assert.IsTrue ((from t in tree.LargerThanOrEqualTo(0) select t.Item1).SequenceEqual(new double[] { 1, 8 }));

			tree.Delete (1);
			Assert.IsTrue ((from t in tree.LargerThanOrEqualTo(0) select t.Item1).SequenceEqual(new double[] { 8 }));

			tree.Delete (8);
			Assert.IsTrue ((from t in tree.LargerThanOrEqualTo(0) select t.Item1).Count() == 0);
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:24,代码来源:BTreeDeletionTest.cs

示例7: TestSavingEmptyTree

		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);
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:39,代码来源:PersistentTreeTest.cs

示例8: BreakNodeTest

		public void BreakNodeTest ()
		{
			// Generate a random sequence
			var seq = new List<double>();
			var rnd = new Random ();
			for (var i = 0; i < 1000; i++) {
				seq.Add (rnd.Next(0, 10));
			}

			// Start inserting
			var tree = new Tree<double, string>(
				new TreeMemoryNodeManager<double, string>(2, Comparer<double>.Default),
				allowDuplicateKeys: true
			);
			foreach (var t in seq) {
				tree.Insert (t, t.ToString());
			}

			// Test 1
			{
				var keys = (from t in tree.LargerThanOrEqualTo(0) select t.Item1).ToArray();
				Assert.AreEqual (seq.Count, keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, seq), OccurencesInList(key, keys));
				}
			}

			// Test 2
			{
				var keys = (from t in tree.LargerThanOrEqualTo(7) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t >= 7 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t >= 7 select t), OccurencesInList(key, keys));
				}
			}

			// Test 3
			{
				var keys = (from t in tree.LargerThan(7) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t > 7 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t > 7 select t), OccurencesInList(key, keys));
				}
			}

			// Test 4
			{
				var keys = (from t in tree.LargerThanOrEqualTo(7.5) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t >= 7.5 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t >= 7 select t), OccurencesInList(key, keys));
				}
			}

			// Test 5
			{
				var keys = (from t in tree.LargerThan(7.5) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t > 7.5 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t > 7.5 select t), OccurencesInList(key, keys));
				}
			}

			// Test 6
			{
				var keys = (from t in tree.LessThan(7) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t < 7 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t < 7 select t), OccurencesInList(key, keys));
				}
			}

			// Test 7
			{
				var keys = (from t in tree.LessThan(7.5) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t < 7.5 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t < 7.5 select t), OccurencesInList(key, keys));
				}
			}

			// Test 8
			{
				var keys = (from t in tree.LessThanOrEqualTo(7) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t <= 7 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t <= 7 select t), OccurencesInList(key, keys));
				}
			}

			// Test 9
			{
				var keys = (from t in tree.LessThanOrEqualTo(7.5) select t.Item1).ToArray();
				Assert.AreEqual ((from t in seq where t <= 7.5 select t).Count(), keys.Length);
				foreach (var key in keys) {
					Assert.AreEqual (OccurencesInList(key, from t in seq where t <= 7.5 select t), OccurencesInList(key, keys));
				}
			}
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:99,代码来源:BTreeNonUniqueTest.cs

示例9: TestSavingFullTree

		public void TestSavingFullTree ()
		{
			// Create a tree with random elements,
			// presist it in a memory stream and then reconstruct it
			BasicConfigurator.Configure ();

			var stream = new MemoryStream ();
			var tree = new Tree<int, long>(
				new TreeDiskNodeManager<int, long> (
					new TreeIntSerializer(),
					new TreeLongSerializer(),
					new RecordStorage(
						new BlockStorage(
							stream, 
							4096, 
							48
						)
					)
				), 
				true
			);

			// Generate 10000 elements
			var sampleData = new List<Tuple<int, long>>();
			var rnd = new Random ();
			for (var i = 0; i < 1000; i++)
			{
				sampleData.Add (new Tuple<int, long>(
					rnd.Next(Int32.MinValue, Int32.MaxValue), 
					(long)rnd.Next(Int32.MinValue, Int32.MaxValue)
				));
			}

			// Insert these elements into the tree
			foreach (var d in sampleData) {
				tree.Insert (d.Item1, d.Item2);

				// Now create new tree see if changes were saved to the underlying stream
				var tree2 = new Tree<int, long>(
					new TreeDiskNodeManager<int, long> (
						new TreeIntSerializer(),
						new TreeLongSerializer(),
						new RecordStorage(
							new BlockStorage(
								stream, 
								4096, 
								48
							)
						)
					), 
					true
				);
				var actual = (from i in tree2.LargerThanOrEqualTo (Int32.MinValue) select i).ToList();
				var expected = (from i in tree.LargerThanOrEqualTo(Int32.MinValue) select i).ToList();
				Assert.IsTrue (actual.SequenceEqual (expected));
			}

			// Test deletion of some lemenets
			for (var i = 0; i < sampleData.Count; i++) {
				var deleteAt = rnd.Next (0, sampleData.Count);
				var deleteKey = sampleData[deleteAt];
				sampleData.RemoveAt (deleteAt);
				tree.Delete (deleteKey.Item1, deleteKey.Item2);

				// Now create new tree see if changes were saved to the underlying stream
				var tree2 = new Tree<int, long>(
					new TreeDiskNodeManager<int, long> (
						new TreeIntSerializer(),
						new TreeLongSerializer(),
						new RecordStorage(
							new BlockStorage(
								stream, 
								4096, 
								48
							)
						)
					), 
					true
				);
				var actual   = (from ii in tree2.LargerThanOrEqualTo (Int32.MinValue) select ii.Item1).ToList();
				var expected = (from ii in tree.LargerThanOrEqualTo(Int32.MinValue) select ii.Item1).ToList();
				Assert.IsTrue (actual.SequenceEqual (expected));
			}
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:84,代码来源:PersistentTreeTest.cs

示例10: NonUniqueTreeTestWithDuplicateKeys

		public void NonUniqueTreeTestWithDuplicateKeys ()
		{
			
			// Unique tree
			var expectedRemain = new List<Tuple<double, string>>();
			var tree = new Tree<double, string>(
				new TreeMemoryNodeManager<double, string>(2, Comparer<double>.Default),
				true
			);
			/*
			tree.Insert (1, "A");
			tree.Insert (1, "B");
			tree.Insert (1, "C");
			tree.Insert (1, "D");
			tree.Insert (1, "E");
			tree.Insert (1, "F");
			tree.Insert (1, "G");
			tree.Insert (1, "H");

			tree.Delete (1, "E");
			var remain = (from entry in tree.LargerThanOrEqualTo(0) select entry.Item2).ToArray();
			Assert.IsTrue (remain.SequenceEqual(
				new List<string>{
					"A",
					"B",
					"C",
					"D",
					"F",
					"G",
					"H"
				}
			)); */

			// Insert random numbers
			var rnd = new Random ();
			for (var i = 0; i < 1000; i++) {
				tree.Insert (i, "A");
				expectedRemain.Add (new Tuple<double, string>(i, "A"));

				var dupCount = rnd.Next (0, 3);
				for (var t = 0; t < dupCount; t++) {
					if (t == 0) {
						tree.Insert (i, "B");
						expectedRemain.Add (new Tuple<double, string>(i, "B"));
					} else if (t == 1) {
						tree.Insert (i, "C");
						expectedRemain.Add (new Tuple<double, string>(i, "C"));
					} else {
						throw new Exception ();
					}
				}
			}


			// Start deleting randomly
			for (var i = 0; i < 1000; i++) {
				var deleteAt = rnd.Next (0, expectedRemain.Count);
				var keyToDelete = expectedRemain[deleteAt];
				expectedRemain.RemoveAt (deleteAt);
				tree.Delete (keyToDelete.Item1, keyToDelete.Item2);
				var remain = (from entry in tree.LargerThanOrEqualTo(0) orderby entry.Item1, entry.Item2 select entry).ToArray();
				Assert.IsTrue (remain.SequenceEqual (expectedRemain));
			} 
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:64,代码来源:BTreeDeletionTest.cs

示例11: RandomTest

		public void RandomTest ()
		{
			var tree = new Tree<int, string>(new TreeMemoryNodeManager<int, string>(2, Comparer<int>.Default));

			// Generate a random sequence
			var seq = new List<int>();
			var rnd = new Random (198);

			// Insert random sequence 
			for (var i = 0; i < 1000; i++)
			{
				var n = rnd.Next (0, 2000);
				while (seq.Contains(n) == true) {
					n = rnd.Next (0, 2000);
				}

				tree.Insert (n, n.ToString());
				seq.Add (n);
			}

			// Validate result
			var sortedSeq = seq.FindAll (t => true);
			sortedSeq.Sort (Comparer<int>.Default);
			Assert.IsTrue (sortedSeq.SequenceEqual(from tuple in tree.LargerThanOrEqualTo(0) select tuple.Item1));

			// Randomly query
			for (var n = 0; n <= 100; n++)
			{
				var number = n = rnd.Next (0, 2000);
				var lastD = 0;
				foreach (var d in from tuple in tree.LargerThanOrEqualTo(number) select tuple.Item1)
				{
					Assert.IsTrue (d >= number);
					Assert.IsTrue (d > lastD);
					lastD = d;
				}


				lastD = 0;
				foreach (var d in from tuple in tree.LargerThan(number) select tuple.Item1)
				{
					Assert.IsTrue (d > number);
					Assert.IsTrue (d > lastD);
					lastD = d;
				}

				lastD = 999999;
				foreach (var d in from tuple in tree.LessThan(number) select tuple.Item1)
				{
					Assert.IsTrue (d < number);
					Assert.IsTrue (d < lastD);
					lastD = d;
				}

				lastD = 999999;
				foreach (var d in from tuple in tree.LessThanOrEqualTo(number) select tuple.Item1)
				{
					Assert.IsTrue (d <= number);
					Assert.IsTrue (d < lastD);
					lastD = d;
				}
			}
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:63,代码来源:BTreeTest.cs

示例12: SplitChildNodeTest

		public void SplitChildNodeTest ()
		{
			// Insert too much at root node that it overvlow
			var tree = new Tree<int, string>(new TreeMemoryNodeManager<int, string>(2, Comparer<int>.Default));

			for (var i = 0; i <= 100; i++)
			{
				tree.Insert (i, i.ToString());
				var result = (from tuple in tree.LargerThanOrEqualTo(0) select tuple.Item1).ToList();
				Assert.AreEqual (i + 1, result.Count);
			}
		}
开发者ID:K-Eo,项目名称:FooDB,代码行数:12,代码来源:BTreeTest.cs


注:本文中的Tree.LargerThanOrEqualTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。