本文整理汇总了C#中RedBlackTree类的典型用法代码示例。如果您正苦于以下问题:C# RedBlackTree类的具体用法?C# RedBlackTree怎么用?C# RedBlackTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RedBlackTree类属于命名空间,在下文中一共展示了RedBlackTree类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: BuildStorageEntry
private static int BuildStorageEntry(DirectoryEntry storageEntry)
{
// direct members of each storage are organised in a separate red-black tree
RedBlackTree<DirectoryEntry> rbTree = new RedBlackTree<DirectoryEntry>();
foreach (DirectoryEntry entry in storageEntry.Members.Values)
{
rbTree.Add(entry);
}
foreach (RedBlackTreeNode<DirectoryEntry> node in rbTree.InorderTreeWalk(rbTree.Root))
{
DirectoryEntry entry = node.Data;
entry.NodeColor = GetNodeColor(node.Color);
entry.LeftChildDID = GetNodeID(node.Left);
entry.RightChildDID = GetNodeID(node.Right);
if (entry.Members.Count > 0)
{
entry.EntryType = EntryType.Storage;
entry.MembersTreeNodeDID = BuildStorageEntry(entry);
}
else
{
entry.EntryType = EntryType.Stream;
entry.MembersTreeNodeDID = -1;
}
}
return rbTree.Root.Data.ID;
}
开发者ID:Johnnyfly,项目名称:source20131023,代码行数:30,代码来源:DirectoryTree.cs
示例2: EmptyTreeTest
public void EmptyTreeTest()
{
var tree = new RedBlackTree<Int32>();
Assert.IsTrue(tree.IsEmpty);
Assert.IsFalse(tree.BredthContains(2));
}
开发者ID:jramey,项目名称:BinaryTree,代码行数:7,代码来源:RedBlackTreeTests.cs
示例3: ExceptionNullKey
public void ExceptionNullKey()
{
var redBlackTree = new RedBlackTree<object, string>
{
{null, "a"}
};
}
开发者ID:GTuritto,项目名称:ngenerics,代码行数:7,代码来源:Add.cs
示例4: RotationTests
public void RotationTests()
{
var tree = new RedBlackTree<Int32>();
tree.Insert(35);
tree.Insert(25);
tree.Insert(70);
tree.Insert(10);
tree.Insert(100);
tree.Insert(20);
tree.Insert(5);
tree.Insert(85);
tree.Insert(55);
tree.Insert(40);
Assert.AreEqual(35, tree.RootNode.NodeValue);
Assert.AreEqual(20, tree.RootNode.LeftNode.NodeValue);
Assert.AreEqual(25, tree.RootNode.LeftNode.RightNode.NodeValue);
Assert.AreEqual(10, tree.RootNode.LeftNode.LeftNode.NodeValue);
Assert.AreEqual(5, tree.RootNode.LeftNode.LeftNode.LeftNode.NodeValue);
Assert.AreEqual(85, tree.RootNode.RightNode.NodeValue);
Assert.AreEqual(100, tree.RootNode.RightNode.RightNode.NodeValue);
Assert.AreEqual(55, tree.RootNode.RightNode.LeftNode.NodeValue);
Assert.AreEqual(40, tree.RootNode.RightNode.LeftNode.LeftNode.NodeValue);
Assert.AreEqual(70, tree.RootNode.RightNode.LeftNode.RightNode.NodeValue);
}
开发者ID:jramey,项目名称:BinaryTree,代码行数:27,代码来源:RedBlackTreeTests.cs
示例5: NonIComparable
public void NonIComparable()
{
var redBlackTree = new RedBlackTree<NonComparableTClass, string>();
for (var i = 0; i < 100; i++)
{
redBlackTree.Add(new NonComparableTClass(i), i.ToString());
}
var newTree = SerializeUtil.BinarySerializeDeserialize(redBlackTree);
Assert.AreNotSame(redBlackTree, newTree);
Assert.AreEqual(redBlackTree.Count, newTree.Count);
var redBlackTreeEnumerator = redBlackTree.GetEnumerator();
var newTreeEnumerator = newTree.GetEnumerator();
while (redBlackTreeEnumerator.MoveNext())
{
Assert.IsTrue(newTreeEnumerator.MoveNext());
Assert.AreEqual(redBlackTreeEnumerator.Current.Key.Number, newTreeEnumerator.Current.Key.Number);
Assert.AreEqual(redBlackTreeEnumerator.Current.Value, newTreeEnumerator.Current.Value);
Assert.IsTrue(newTree.ContainsKey(redBlackTreeEnumerator.Current.Key));
Assert.AreEqual(newTree[redBlackTreeEnumerator.Current.Key], redBlackTreeEnumerator.Current.Value);
}
Assert.IsFalse(newTreeEnumerator.MoveNext());
}
开发者ID:GTuritto,项目名称:ngenerics,代码行数:29,代码来源:Serialization.cs
示例6: ExceptionKeyAlreadyInTree
public void ExceptionKeyAlreadyInTree()
{
var redBlackTree = new RedBlackTree<int, string>
{
{0, "50"},
{0, "20"}
};
}
开发者ID:GTuritto,项目名称:ngenerics,代码行数:8,代码来源:Add.cs
示例7: AddExample
public void AddExample()
{
// Create a simple tree
var tree = new RedBlackTree<string, int> {{"cat", 1}, {"dog", 2}, {"canary", 3}};
// There should be 3 items in the tree.
Assert.AreEqual(3, tree.Count);
}
开发者ID:GTuritto,项目名称:ngenerics,代码行数:8,代码来源:RedBlackTreeExamples.cs
示例8: RootNodeTest
public void RootNodeTest()
{
var tree = new RedBlackTree<Int32>();
tree.Insert(10);
Assert.IsFalse(tree.IsEmpty);
Assert.IsTrue(tree.BredthContains(10));
Assert.AreEqual(10, tree.RootNode.NodeValue);
}
开发者ID:jramey,项目名称:BinaryTree,代码行数:9,代码来源:RedBlackTreeTests.cs
示例9: ContainsFailureTest
public void ContainsFailureTest()
{
var tree = new RedBlackTree<Int32>();
tree.Insert(10);
tree.Insert(25);
tree.Insert(7);
Assert.IsFalse(tree.BredthContains(2));
}
开发者ID:jramey,项目名称:BinaryTree,代码行数:10,代码来源:RedBlackTreeTests.cs
示例10: ContainsSuccessTest
public void ContainsSuccessTest()
{
var tree = new RedBlackTree<Int32>();
tree.Insert(10);
tree.Insert(25);
tree.Insert(7);
Assert.IsTrue(tree.BredthContains(25));
}
开发者ID:jramey,项目名称:BinaryTree,代码行数:10,代码来源:RedBlackTreeTests.cs
示例11: Simple
public void Simple()
{
var redBlackTree = new RedBlackTree<int, string>();
Assert.AreEqual(redBlackTree.Count, 0);
Assert.IsTrue(redBlackTree.Comparer is KeyValuePairComparer<int, string>);
redBlackTree = new RedBlackTree<int, string>(new ReverseComparer<int>());
Assert.AreEqual(redBlackTree.Count, 0);
Assert.IsTrue(redBlackTree.Comparer.GetType().IsAssignableFrom(typeof(KeyValuePairComparer<int, string>)));
}
开发者ID:GTuritto,项目名称:ngenerics,代码行数:10,代码来源:Contruction.cs
示例12: GetTestTree
internal static RedBlackTree<int, string> GetTestTree(int noOfItems)
{
var redBlackTree = new RedBlackTree<int, string>();
for (var i = 0; i < noOfItems; i++)
{
redBlackTree.Add(i, i.ToString());
}
return redBlackTree;
}
开发者ID:havok,项目名称:ngenerics,代码行数:11,代码来源:RedBlackTreeTest.cs
示例13: AddItem
public void AddItem()
{
RedBlackTree<int, int> tree = new RedBlackTree<int, int>();
int temp;
tree.Add(1, 1);
Assert.AreEqual(tree.Count, 1);
Assert.IsTrue(tree.TryGetValue(1, out temp));
Assert.IsFalse(tree.TryGetValue(2, out temp));
}
开发者ID:CedricDumont,项目名称:NMemory.Next,代码行数:11,代码来源:RedBlackTreeFixture.cs
示例14: Simple
public void Simple()
{
var redBlackTree = GetTestTree();
Assert.IsFalse(redBlackTree.IsEmpty);
redBlackTree.Clear();
Assert.IsTrue(redBlackTree.IsEmpty);
redBlackTree = new RedBlackTree<int, string>();
Assert.IsTrue(redBlackTree.IsEmpty);
}
开发者ID:havok,项目名称:ngenerics,代码行数:11,代码来源:Count.cs
示例15: AddTest
public void AddTest()
{
//Arrange
var bst = new RedBlackTree<int, string>();
// 33 28 63 20 31 39 79 10 35 60 ( red links = 10 39 )
var testData = new[]
{
new KeyValuePair<int, string>(33, "33"),
new KeyValuePair<int, string>(28, "28"),
new KeyValuePair<int, string>(63, "63"),
new KeyValuePair<int, string>(20, "20"),
new KeyValuePair<int, string>(31, "31"),
new KeyValuePair<int, string>(39, "39"),
new KeyValuePair<int, string>(79, "79"),
new KeyValuePair<int, string>(10, "10"),
new KeyValuePair<int, string>(35, "35"),
new KeyValuePair<int, string>(60, "60"),
};
//Act
Array.ForEach(testData, t =>
{
bst.Add(t.Key, t.Value);
});
bst.Add(75, "75");
bst.Add(38, "38");
bst.Add(12, "12");
var result = bst.LevelOrderTraversal();
//Assert
Assert.AreEqual(result.ElementAt(0).Key, 33);
Assert.AreEqual(result.ElementAt(1).Key, 28);
Assert.AreEqual(result.ElementAt(2).Key, 63);
Assert.AreEqual(result.ElementAt(3).Key, 12);
Assert.AreEqual(result.ElementAt(4).Key, 31);
Assert.AreEqual(result.ElementAt(5).Key, 39);
Assert.AreEqual(result.ElementAt(6).Key, 79);
Assert.AreEqual(result.ElementAt(7).Key, 10);
Assert.AreEqual(result.ElementAt(8).Key, 20);
Assert.AreEqual(result.ElementAt(9).Key, 38);
Assert.AreEqual(result.ElementAt(10).Key, 60);
Assert.AreEqual(result.ElementAt(11).Key, 75);
Assert.AreEqual(result.ElementAt(12).Key, 35);
//Assert are red nodes
Assert.IsTrue(result.ElementAt(3).IsRed);
Assert.IsTrue(result.ElementAt(5).IsRed);
Assert.IsTrue(result.ElementAt(11).IsRed);
}
开发者ID:GrigoryBushuev,项目名称:Algo,代码行数:53,代码来源:LLRBTreeTest.cs
示例16: LevelOrderTraversalTest
public void LevelOrderTraversalTest()
{
//Arrange
var bst = new RedBlackTree<int, string>();
//70 40 81 13 57 75 85 10 32 48 66 82 43
var testData = new[]
{
new KeyValuePair<int, string>(70, "70"),
new KeyValuePair<int, string>(40, "40"),
new KeyValuePair<int, string>(81, "81"),
new KeyValuePair<int, string>(13, "13"),
new KeyValuePair<int, string>(57, "57"),
new KeyValuePair<int, string>(75, "75"),
new KeyValuePair<int, string>(85, "85"),
new KeyValuePair<int, string>(10, "10"),
new KeyValuePair<int, string>(32, "32"),
new KeyValuePair<int, string>(48, "48"),
new KeyValuePair<int, string>(66, "66"),
new KeyValuePair<int, string>(82, "82"),
new KeyValuePair<int, string>(43, "43"),
};
//Act
Array.ForEach(testData, t =>
{
bst.Add(t.Key, t.Value);
});
var result = bst.LevelOrderTraversal();
//Assert
Assert.AreEqual(result.ElementAt(0).Key, 70);
Assert.AreEqual(result.ElementAt(1).Key, 40);
Assert.AreEqual(result.ElementAt(2).Key, 81);
Assert.AreEqual(result.ElementAt(3).Key, 13);
Assert.AreEqual(result.ElementAt(4).Key, 57);
Assert.AreEqual(result.ElementAt(5).Key, 75);
Assert.AreEqual(result.ElementAt(6).Key, 85);
Assert.AreEqual(result.ElementAt(7).Key, 10);
Assert.AreEqual(result.ElementAt(8).Key, 32);
Assert.AreEqual(result.ElementAt(9).Key, 48);
Assert.AreEqual(result.ElementAt(10).Key, 66);
Assert.AreEqual(result.ElementAt(11).Key, 82);
Assert.AreEqual(result.ElementAt(12).Key, 43);
//Assert are red nodes
Assert.IsTrue(result.ElementAt(1).IsRed);
Assert.IsTrue(result.ElementAt(12).IsRed);
Assert.IsTrue(result.ElementAt(11).IsRed);
}
开发者ID:GrigoryBushuev,项目名称:Algo,代码行数:52,代码来源:LLRBTreeTest.cs
示例17: TestRemoveBug
public void TestRemoveBug ()
{
var tree = new RedBlackTree<TestNode> ();
TestNode t1 = new TestNode (1);
TestNode t2 = new TestNode (2);
TestNode t3 = new TestNode (3);
tree.Add (t1);
tree.InsertRight (t1, t2);
tree.InsertLeft (t1, t3);
tree.Remove (t1);
Assert.AreEqual (2, tree.Count);
}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:13,代码来源:RedBlackTreeTests.cs
示例18: RemoveNonExistingItem
public void RemoveNonExistingItem()
{
RedBlackTree<int, int> tree = new RedBlackTree<int, int>();
tree.Add(1, 1);
int temp;
bool removed = tree.Remove(2);
Assert.IsFalse (removed);
Assert.AreEqual(tree.Count, 1);
Assert.IsTrue(tree.TryGetValue(1, out temp));
Assert.IsFalse(tree.TryGetValue(2, out temp));
}
开发者ID:CedricDumont,项目名称:NMemory.Next,代码行数:14,代码来源:RedBlackTreeFixture.cs
示例19: Main
static void Main(string[] args)
{
var stack = new Stack<string>();
var tree = new RedBlackTree<string, string>();
var dict = new Dictionary<string, string>();
for (int i = 0; i < 1000000; i++)
{
stack.Push(Guid.NewGuid().ToString());
}
var sw = new Stopwatch();
sw.Start();
foreach (string item in stack)
{
tree.Add(item, item);
}
sw.Stop();
System.Console.WriteLine("{0}", sw.Elapsed);
sw.Reset();
sw.Start();
foreach (string item in stack)
{
dict.Add(item, item);
}
sw.Stop();
System.Console.WriteLine("{0}", sw.Elapsed);
sw.Reset();
sw.Start();
foreach (string item in stack)
{
tree.ContainsKey(item);
}
sw.Stop();
System.Console.WriteLine("{0}", sw.Elapsed);
sw.Reset();
sw.Start();
foreach (string item in stack)
{
dict.ContainsKey(item);
}
sw.Stop();
System.Console.WriteLine("{0}", sw.Elapsed);
System.Console.ReadKey();
}
开发者ID:stemarie,项目名称:performance,代码行数:49,代码来源:Program.cs
示例20: CalcOffset
public long CalcOffset (RedBlackTree<TreeNode>.RedBlackTreeNode Node)
{
RedBlackTree<TreeNode>.RedBlackTreeNode cur = Node;
long offset = cur.left != null ? cur.left.value.TotalLength : 0;
while (cur.parent != null) {
if (cur == cur.parent.right) {
if (cur.parent.left != null && cur.parent.left.value != null)
offset += cur.parent.left.value.TotalLength;
if (Node.parent.value != null)
offset += cur.parent.value.Length;
}
cur = cur.parent;
}
return offset;
}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:15,代码来源:PieceTable.cs
注:本文中的RedBlackTree类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论