本文整理汇总了C#中RedBlackTree.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# RedBlackTree.Clear方法的具体用法?C# RedBlackTree.Clear怎么用?C# RedBlackTree.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBlackTree
的用法示例。
在下文中一共展示了RedBlackTree.Clear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Simple
public void Simple()
{
var redBlackTree = new RedBlackTree<int, string>();
Assert.IsTrue(redBlackTree.IsEmpty);
redBlackTree = GetTestTree();
Assert.IsFalse(redBlackTree.IsEmpty);
redBlackTree.Clear();
Assert.IsTrue(redBlackTree.IsEmpty);
}
示例2: ClearExample
public void ClearExample()
{
// Create a simple tree
var tree = new RedBlackTree<string, int>
{
new KeyValuePair<string, int>("cat", 1),
new KeyValuePair<string, int>("dog", 2),
new KeyValuePair<string, int>("canary", 3)
};
// There should be 3 items in the tree.
Assert.AreEqual(3, tree.Count);
// Clear the tree
tree.Clear();
// The tree should be empty.
Assert.AreEqual(0, tree.Count);
// No cat here..
Assert.IsFalse(tree.ContainsKey("cat"));
}
示例3: IsEmptyExample
public void IsEmptyExample()
{
var tree = new RedBlackTree<string, int>();
// Tree is empty.
Assert.IsTrue(tree.IsEmpty);
// Add a cat.
tree.Add(new KeyValuePair<string, int>("cat", 1));
// Tree is not empty.
Assert.IsFalse(tree.IsEmpty);
// Clear the tree - thereby removing all items contained.
tree.Clear();
// Tree is empty again with count = 0.
Assert.IsTrue(tree.IsEmpty);
}
示例4: CountExample
public void CountExample()
{
var tree = new RedBlackTree<string, int>();
// Tree count is 0.
Assert.AreEqual(0, tree.Count);
// Add a cat.
tree.Add(new KeyValuePair<string, int>("cat", 1));
// Tree count is 1.
Assert.AreEqual(1, tree.Count);
// Add a dog
tree.Add(new KeyValuePair<string, int>("dog", 2));
// Tree count is 2.
Assert.AreEqual(2, tree.Count);
// Clear the tree - thereby removing all items contained.
tree.Clear();
// Tree is empty again with 0 count.
Assert.AreEqual(0, tree.Count);
}
示例5: button4_Click
private void button4_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
Stopwatch sw = new Stopwatch();
TimeSpan slTime = TimeSpan.MinValue;
TimeSpan treeTime = TimeSpan.MaxValue;
Random rng = new Random();
SortedDictionary<int, int> sl = new SortedDictionary<int, int>();
RedBlackTree<int, int> tree = new RedBlackTree<int, int>();
sb.Append("1 tick = ");
sb.Append((int)(1000000000d / ((double)Stopwatch.Frequency)));
sb.AppendLine(" nano seconds");
sb.AppendLine(" Entries | SL in ms | RBT adj || SL ticks | RBT adj | % Time Spent");
const long MaxRotations = 1000;
const long MinInsert = 99999;
const long MaxInsert = 100000;
long[,] slData = new long[MaxInsert - MinInsert + 1, MaxRotations];
long[,] treeData = new long[MaxInsert - MinInsert + 1, MaxRotations];
double[] slData2 = new double[MaxInsert - MinInsert + 1];
double[] treeData2 = new double[MaxInsert - MinInsert + 1];
for (long j = MinInsert; j <= MaxInsert; j++)
for (long k = 0L; k < MaxRotations; k++)
{
sl.Clear();
tree.Clear();
int rngValue = rng.Next();
sw.Start();
for (int i = 0; i < j; i++)
sl[rngValue] = rngValue;
sw.Stop();
slTime = sw.Elapsed;
sw.Reset();
sw.Start();
for (int i = 0; i < j; i++)
tree.Insert(rngValue, rngValue, true);
sw.Stop();
treeTime = sw.Elapsed;
sw.Reset();
slData[j - MinInsert, k] = slTime.Ticks;
treeData[j - MinInsert, k] = treeTime.Ticks;
}
for (long j = MinInsert; j <= MaxInsert; j++)
{
long slSum = 0, treeSum = 0;
for (int k = 0; k < MaxRotations; k++)
{
slSum += slData[j - MinInsert, k];
treeSum += treeData[j - MinInsert, k];
}
slData2[j - MinInsert] = (double)slSum / (double)MaxRotations;
treeData2[j - MinInsert] = (double)treeSum / (double)MaxRotations;
}
for (long j = MinInsert; j <= MaxInsert; j++)
{
sb.Append(j.ToString().PadLeft(8));
sb.Append(" |");
sb.Append(string.Empty.PadLeft(9));
sb.Append(" |");
sb.Append(string.Empty.PadLeft(8));
sb.Append(" ||");
sb.Append(slData2[j - MinInsert].ToString("F2").PadLeft(9));
sb.Append(" |");
sb.Append((treeData2[j - MinInsert] - slData2[j - MinInsert]).ToString("F2").PadLeft(8));
sb.Append(" |");
sb.Append((treeData2[j - MinInsert] / slData2[j - MinInsert] * 100d).ToString("F2").PadLeft(13));
sb.AppendLine();
}
tbOut.Text = sb.ToString();
}
示例6: button3_Click
private void button3_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
Stopwatch sw = new Stopwatch();
TimeSpan slTime = TimeSpan.MinValue;
TimeSpan treeTime = TimeSpan.MaxValue;
//int[] testValue = new int[500000];
Random rng = new Random();
//for (int i = 0; i < testValue.Length; i++)
//{
// testValue[i] = rng.Next();
//}
SortedDictionary<int, int> sl = new SortedDictionary<int, int>();
RedBlackTree<int, int> tree = new RedBlackTree<int, int>();
sb.Append("1 tick = ");
sb.Append((int)(1000000000d / ((double)Stopwatch.Frequency)));
sb.AppendLine(" nano seconds");
sb.AppendLine(" Entries | SL in ms | RBT adj || SL ticks | RBT adj | % Time Spent");
const int MaxInsert = 100001;
for (int k = 1; k < MaxInsert; k *= 10)
for (int j = k; j < k * 10 && j < MaxInsert; j += k)
{
sl.Clear();
tree.Clear();
int rngValue = rng.Next();
sw.Start();
for (int i = 0; i < j; i++)
sl[rngValue] = rngValue;
sw.Stop();
slTime = sw.Elapsed;
sw.Reset();
sw.Start();
for (int i = 0; i < j; i++)
tree.Insert(rngValue, rngValue, true);
sw.Stop();
treeTime = sw.Elapsed;
sw.Reset();
sb.Append(j.ToString().PadLeft(8));
sb.Append(" |");
sb.Append(slTime.Milliseconds.ToString().PadLeft(9));
sb.Append(" |");
sb.Append((treeTime.Milliseconds - slTime.Milliseconds).ToString().PadLeft(8));
sb.Append(" ||");
sb.Append(slTime.Ticks.ToString().PadLeft(9));
sb.Append(" |");
sb.Append((treeTime.Ticks - slTime.Ticks).ToString().PadLeft(8));
sb.Append(" |");
sb.Append(((double)treeTime.Ticks / (double)slTime.Ticks * 100d).ToString("F2").PadLeft(13));
sb.AppendLine();
}
tbOut.Text = sb.ToString();
}