本文整理汇总了C#中SortedMap.GetCursor方法的典型用法代码示例。如果您正苦于以下问题:C# SortedMap.GetCursor方法的具体用法?C# SortedMap.GetCursor怎么用?C# SortedMap.GetCursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedMap
的用法示例。
在下文中一共展示了SortedMap.GetCursor方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CouldMoveAsyncOnEmptySM
public void CouldMoveAsyncOnEmptySM() {
var sm = new SortedMap<DateTime, double>();
var c = sm.GetCursor();
var moveTask = c.MoveNext(CancellationToken.None);
sm.Add(DateTime.UtcNow.Date.AddSeconds(0), 0);
var result = moveTask.Result;
Assert.IsTrue(result);
}
示例2: CouldEnumerateGrowingSM
public void CouldEnumerateGrowingSM() {
var count = 1000000;
var sw = new Stopwatch();
sw.Start();
var sm = new SortedMap<DateTime, double>();
var c = sm.GetCursor();
for (int i = 0; i < count; i++) {
sm.Add(DateTime.UtcNow.Date.AddSeconds(i), i);
c.MoveNext();
Assert.AreEqual(i, c.CurrentValue);
}
sw.Stop();
Console.WriteLine("Elapsed msec: {0}", sw.ElapsedMilliseconds - 50);
Console.WriteLine("Ops: {0}", Math.Round(0.000001 * count * 1000.0 / (sw.ElapsedMilliseconds * 1.0), 2));
}
示例3: CouldMoveAtGE
public void CouldMoveAtGE() {
var scm = new SortedMap<int, int>(50);
for (int i = 0; i < 100; i++) {
scm[i] = i;
}
var cursor = scm.GetCursor();
cursor.MoveAt(-100, Lookup.GE);
Assert.AreEqual(0, cursor.CurrentKey);
Assert.AreEqual(0, cursor.CurrentValue);
var shouldBeFalse = cursor.MoveAt(-100, Lookup.LE);
Assert.IsFalse(shouldBeFalse);
}
示例4: CouldZipMillionIntsMovePreviousBenchmark
public void CouldZipMillionIntsMovePreviousBenchmark() {
var sw = new Stopwatch();
var sm1 = new SortedMap<int, int>();
sm1.Add(0, 0);
for (int i = 2; i < 1000000; i++) {
sm1.Add(i, i);
}
var series = new[] { sm1, sm1, sm1, sm1, sm1, };// sm1, sm1, sm1, sm1, sm1, sm1, sm1, sm1, sm1, sm1, sm1, sm1, sm1, sm1, sm1, };
sw.Start();
var cur = series.Zip((k, varr) => varr.Sum()).GetCursor();
var totalSum = 0L;
while (cur.MovePrevious()) {
totalSum += cur.CurrentValue;
}
var expectedTotalSum = 0L;
var cur2 = sm1.GetCursor();
while (cur2.MovePrevious()) {
expectedTotalSum += cur2.CurrentValue;
}
expectedTotalSum *= 5;
sw.Stop();
Assert.AreEqual(expectedTotalSum, totalSum, "Sums are not equal");
Console.WriteLine("Elapsed msec: {0}", sw.ElapsedMilliseconds);
Console.WriteLine("Total sum: {0}", totalSum);
}
示例5: CouldNotMoveAsyncContinuousOnEmptyZip
public void CouldNotMoveAsyncContinuousOnEmptyZip() {
var sm1 = new SortedMap<int, int>();
var sm2 = new SortedMap<int, int>();
sm1.IsMutable = false;
sm2.IsMutable = false;
var zipped = sm1.Repeat() + sm2.Repeat();
var c1 = zipped.GetCursor();
Assert.IsFalse(sm1.GetCursor().MoveNext(CancellationToken.None).Result);
Assert.IsFalse(sm2.GetCursor().MoveNext(CancellationToken.None).Result);
Assert.IsFalse(c1.MoveNext());
Assert.IsFalse(c1.MoveFirst());
var task = c1.MoveNext(CancellationToken.None);
task.Wait();
Assert.AreEqual(TaskStatus.RanToCompletion, task.Status);
Assert.IsFalse(task.Result);
}
示例6: MoveNextAsyncBenchmark
public void MoveNextAsyncBenchmark() {
// this benchmark shows that simple async enumeration gives 13+ mops,
// this means than we should use parallel enumeration on joins.
// the idea is that a chain of calculations could be somewhat heavy, e.g. rp(ma(log(zipLag(c p -> c/p))))
// but they are optimized for single thread: when movenext is called on the outer cursor,
// the whole chain enumerates synchronously.
// During joins, we must make these evaluations parallel. The net overhead of tasks over existing data is visible
// but not too big, while on real-time stream there is no alternative at all.
// Join algos should be paralell and task-based by default
var count = 10000000;
var sw = new Stopwatch();
var sm = new SortedMap<DateTime, double>();
//sm.IsSynchronized = true;
for (int i = 0; i < count; i++) {
sm.Add(DateTime.UtcNow.Date.AddSeconds(i), i);
}
sm.Complete();
sw.Start();
double sum = 0.0;
var c = sm.GetCursor();
Task.Run(async () => {
while (await c.MoveNext(CancellationToken.None)) {
sum += c.CurrentValue;
}
}).Wait();
sw.Stop();
double expectedSum = 0.0;
for (int i = 0; i < count; i++) {
expectedSum += i;
}
Assert.AreEqual(expectedSum, sum);
Console.WriteLine("Elapsed msec: {0}", sw.ElapsedMilliseconds);
Console.WriteLine("Ops: {0}", Math.Round(0.000001 * count * 1000.0 / (sw.ElapsedMilliseconds * 1.0), 2));
}
示例7: CouldMoveAtLE
public void CouldMoveAtLE() {
var scm = new SortedMap<long, long>();
for (long i = int.MaxValue; i < int.MaxValue*4L; i = i + int.MaxValue) {
scm[i] = i;
}
var cursor = scm.GetCursor();
var shouldBeFalse = cursor.MoveAt(0, Lookup.LE);
Assert.IsFalse(shouldBeFalse);
}