本文整理汇总了C#中SortedMap.Fill方法的典型用法代码示例。如果您正苦于以下问题:C# SortedMap.Fill方法的具体用法?C# SortedMap.Fill怎么用?C# SortedMap.Fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedMap
的用法示例。
在下文中一共展示了SortedMap.Fill方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CouldFillSeries
public void CouldFillSeries() {
var sm = new SortedMap<DateTime, double>();
var sm2 = new SortedMap<DateTime, double>();
var count = 1000000;
for (int i = 0; i < count; i++) {
sm.Add(DateTime.UtcNow.Date.AddSeconds(i * 2), i);
}
for (int i = 0; i < count; i++) {
sm2.Add(DateTime.UtcNow.Date.AddSeconds(i * 2 + 1), i);
}
var expected = 0.0;
for (int i = 0; i < count; i++) {
expected += i; ;
}
var sw = new Stopwatch();
sw.Start();
var sum = (sm.Fill(0) + sm2).Values.Sum();
sw.Stop();
Assert.AreEqual(expected, sum);
Console.WriteLine("Repeat + zip, elapsed: {0}, ops: {1}", sw.ElapsedMilliseconds, (int)((double)count / (sw.ElapsedMilliseconds / 1000.0)));
}
示例2: ZipNFromLogoAndReadmeRepeatFillCouldMoveCursorCorrectly
public void ZipNFromLogoAndReadmeRepeatFillCouldMoveCursorCorrectly()
{
var upper = new SortedMap<int, int> { { 2, 2 }, { 4, 4 } };
var lower = new SortedMap<int, int> { { 1, 10 }, { 3, 30 }, { 5, 50 } };
var sum = (upper.Repeat() + lower.Fill(42));
var cursor = sum.GetCursor();
Assert.IsFalse(cursor.MoveAt(1, Lookup.EQ));
Assert.IsTrue(cursor.MoveAt(1, Lookup.GE));
Assert.AreEqual(2, cursor.CurrentKey);
Assert.AreEqual(44, cursor.CurrentValue);
// move forward
Assert.IsTrue(cursor.MoveNext());
Assert.AreEqual(3, cursor.CurrentKey);
Assert.AreEqual(32, cursor.CurrentValue);
Assert.IsTrue(cursor.MoveNext());
Assert.AreEqual(4, cursor.CurrentKey);
Assert.AreEqual(46, cursor.CurrentValue);
Assert.IsTrue(cursor.MoveNext());
Assert.AreEqual(5, cursor.CurrentKey);
Assert.AreEqual(54, cursor.CurrentValue);
// finished
Assert.IsFalse(cursor.MoveNext());
//// move back
Assert.IsTrue(cursor.MovePrevious());
Assert.AreEqual(4, cursor.CurrentKey);
Assert.AreEqual(46, cursor.CurrentValue);
Assert.IsTrue(cursor.MovePrevious());
Assert.AreEqual(3, cursor.CurrentKey);
Assert.AreEqual(32, cursor.CurrentValue);
Assert.IsTrue(cursor.MovePrevious());
Assert.AreEqual(2, cursor.CurrentKey);
Assert.AreEqual(44, cursor.CurrentValue);
// async moves
Assert.IsTrue(cursor.MoveNext(CancellationToken.None).Result);
Assert.AreEqual(3, cursor.CurrentKey);
Assert.AreEqual(32, cursor.CurrentValue);
Assert.IsTrue(cursor.MoveNext(CancellationToken.None).Result);
Assert.AreEqual(4, cursor.CurrentKey);
Assert.AreEqual(46, cursor.CurrentValue);
Assert.IsTrue(cursor.MoveNext(CancellationToken.None).Result);
Assert.AreEqual(5, cursor.CurrentKey);
Assert.AreEqual(54, cursor.CurrentValue);
var moved = false;
var t = Task.Run(async () =>
{
moved = await cursor.MoveNext(CancellationToken.None);
});
// add new value
upper.Add(6, 6);
t.Wait();
Assert.IsTrue(moved);
Assert.AreEqual(6, cursor.CurrentKey);
Assert.AreEqual(6 + 42, cursor.CurrentValue);
// when all sources are marked as immutable/complete, MNA must return false
var t2 = Task.Run(async () => {
moved = await cursor.MoveNext(CancellationToken.None);
});
upper.Complete();
lower.Complete();
t2.Wait();
Assert.IsFalse(moved);
}
示例3: CouldMoveAtPositionOfThreeDifferentSeriesAllContinuous
public void CouldMoveAtPositionOfThreeDifferentSeriesAllContinuous() {
var sm1 = new SortedMap<int, int>(new Dictionary<int, int>()
{
{ 1, 1},
//{ 2, 2}, // Fill(100)
{ 3, 3},
//{ 5, 5}, // Fill(100)
{ 7, 7}
});
var sm2 = new SortedMap<int, int>(new Dictionary<int, int>()
{
{ 1, 2},
{ 2, 4},
{ 3, 6},
{ 5, 10},
{ 7, 14}
});
var sm3 = new SortedMap<int, int>(new Dictionary<int, int>()
{
{ 1, 3},
{ 2, 6},
{ 3, 9},
{ 5, 15},
{ 7, 21}
});
var series = new[] { sm1.Fill(100), sm2.Repeat(), sm3.Repeat() };
var sum = series.Zip((k, varr) => k * varr.Sum());
var zipNCursor = sum.GetCursor();
var movedAtEQ = zipNCursor.MoveAt(3, Lookup.EQ);
Assert.IsTrue(movedAtEQ);
Assert.AreEqual((3 + 6 + 9) * 3, zipNCursor.CurrentValue);
var movedAtLE = zipNCursor.MoveAt(2, Lookup.LE);
Assert.IsTrue(movedAtLE);
Assert.AreEqual((100 + 4 + 6) * 2, zipNCursor.CurrentValue);
var movedAtGE = zipNCursor.MoveAt(5, Lookup.GE);
Assert.IsTrue(movedAtGE);
Assert.AreEqual((100 + 10 + 15) * 5, zipNCursor.CurrentValue);
var movedAtLT = zipNCursor.MoveAt(3, Lookup.LT);
Assert.IsTrue(movedAtLT);
Assert.AreEqual((100 + 4 + 6) * 2, zipNCursor.CurrentValue);
movedAtLT = zipNCursor.MoveAt(1, Lookup.LT);
Assert.IsTrue(!movedAtLT);
var movedAtGT = zipNCursor.MoveAt(3, Lookup.GT);
Assert.IsTrue(movedAtGT);
Assert.AreEqual((100 + 10 + 15) * 5, zipNCursor.CurrentValue);
movedAtGT = zipNCursor.MoveAt(7, Lookup.GT);
Assert.IsTrue(!movedAtGT);
int val;
var hasGTValue = zipNCursor.TryGetValue(8, out val);
Assert.IsTrue(hasGTValue);
Assert.AreEqual((100 + 14 + 21) * 8, val);
}
示例4: ContinuousZipWithEmptySeriesIsEmpty
public void ContinuousZipWithEmptySeriesIsEmpty() {
var sm1 = new SortedMap<int, int>();
var sm2 = new SortedMap<int, int>();
var rp1 = sm1.Repeat();
var rp2 = sm2.Repeat();
var zip = rp1.Zip(rp2, (l, r) => l + r);
Assert.AreEqual(0, zip.Count());
sm1.Add(1, 1);
var zip2 = rp1.Zip(rp2, (l, r) => l + r);
Assert.AreEqual(0, zip2.Count());
var cursor = zip.GetCursor();
Assert.IsFalse(cursor.MoveNext());
var cursor2 = zip2.GetCursor();
Assert.IsFalse(cursor2.MoveNext());
var fill = sm2.Fill(0);
var zip3 = rp1.Zip(fill, (l, r) => l + r);
Assert.AreEqual(1, zip3.Count());
}
示例5: CouldZipOneEmptyFillSeries
public void CouldZipOneEmptyFillSeries() {
var sm = new SortedMap<DateTime, double>();
var sm2 = new SortedMap<DateTime, double>();
sm2.Add(DateTime.Today, 42.0);
var one = sm.Fill(1.0);
var two = sm2.Fill(2.0);
var three = one + two;
var threeeCursor = three.GetCursor();
Assert.IsTrue(threeeCursor.MoveNext());
Assert.AreEqual(DateTime.Today, threeeCursor.CurrentKey);
Assert.AreEqual(43.0, threeeCursor.CurrentValue);
double v;
Assert.IsTrue(threeeCursor.TryGetValue(DateTime.Now, out v));
Assert.AreEqual(3.0, v);
Assert.IsTrue(three.TryGetValue(DateTime.Now, out v));
Assert.AreEqual(3.0, v);
Assert.IsTrue(three.TryGetValue(DateTime.Today, out v));
Assert.AreEqual(43.0, v);
}
示例6: CouldZipAllEmptyFillSeries
public void CouldZipAllEmptyFillSeries() {
var sm = new SortedMap<DateTime, double>();
var one = sm.Fill(1.0);
var two = sm.Fill(2.0);
var three = one + two;
var threeeCursor = three.GetCursor();
Assert.IsFalse(threeeCursor.MoveNext());
double v;
Assert.IsTrue(threeeCursor.TryGetValue(DateTime.Now, out v));
Assert.AreEqual(3.0, v);
Assert.IsTrue(three.TryGetValue(DateTime.Now, out v));
Assert.AreEqual(3.0, v);
}