本文整理汇总了C#中Sequence.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Sequence.CompareTo方法的具体用法?C# Sequence.CompareTo怎么用?C# Sequence.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sequence
的用法示例。
在下文中一共展示了Sequence.CompareTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testCompareTo
public void testCompareTo() {
var lowScore = new Sequence();
lowScore.Add("A", 1d);
lowScore.Add("B", 2d);
lowScore.Add("C", 3d);
var highScore = new Sequence();
lowScore.Add("A", 7d);
lowScore.Add("B", 8d);
lowScore.Add("C", 9d);
Assert.AreEqual(-1, lowScore.CompareTo(highScore));
Assert.AreEqual(1, highScore.CompareTo(lowScore));
Assert.AreEqual(0, highScore.CompareTo(highScore));
}
示例2: FindSmallerSequence
public static void FindSmallerSequence(List<string> keywords, string filename, ref int start, ref int end)
{
int keywordsCount = 0;
Sequence solution = new Sequence(0, int.MaxValue);
List<int> kwi = new List<int>();
QueueHashtable q = new QueueHashtable(keywords);
using (FileStream fs = File.OpenRead(filename))
{
while (fs.Position < fs.Length)
{
char c = (char) fs.ReadByte();
string currentWord = "";
while (c != ' ')
{
currentWord += c;
c = (char) fs.ReadByte();
}
int i = q.IndexOf(currentWord) - currentWord.Length + 1;
if (q.Kw[i].Key != currentWord)
continue;
if (!q.Kw[i].Value.Any())
keywordsCount++;
q.Kw[i].Value.Enqueue((int) fs.Position - 1);
kwi.Add(i);
if (keywordsCount == keywords.Count)
{
Sequence newSolution = new Sequence(0, 0);
while (keywordsCount == keywords.Count)
{
int index = kwi[0];
kwi.RemoveAt(0);
newSolution.Start = q.Kw[index].Value.Dequeue();
if (!q.Kw[index].Value.Any())
keywordsCount--;
}
newSolution.End = q.Kw[kwi[kwi.Count - 1]].Value.Peek();
if (newSolution.CompareTo(solution) < 0)
{
solution = newSolution;
Console.WriteLine(solution.Start + " - " + solution.End);
Console.WriteLine("##############");
}
}
}
}
start = solution.Start;
end = solution.End;
}
示例3: testClone
public void testClone() {
var sequence = new Sequence();
sequence.Add("a", 10);
sequence.Add("b", 20);
var copy = sequence.Clone() as Sequence;
Assert.NotNull(copy);
Assert.True(sequence.Outcomes.SequenceEqual(copy.Outcomes));
Assert.True(sequence.Probabilities.SequenceEqual(copy.Probabilities));
Assert.True(sequence.CompareTo(copy) == 0);
}