本文整理汇总了C#中SortedMap类的典型用法代码示例。如果您正苦于以下问题:C# SortedMap类的具体用法?C# SortedMap怎么用?C# SortedMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SortedMap类属于命名空间,在下文中一共展示了SortedMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CouldMoveOnFirstAndLastPositionOfThreeSeries
public void CouldMoveOnFirstAndLastPositionOfThreeSeries() {
var sm1 = new SortedMap<int, int>(new Dictionary<int, int>()
{
//{ 1, 1},
{ 2, 2},
//{ 3, 3}
});
var sm2 = new SortedMap<int, int>(new Dictionary<int, int>()
{
{ 1, 2},
{ 2, 4},
{ 3, 6}
});
var sm3 = new SortedMap<int, int>(new Dictionary<int, int>()
{
{ 1, 3},
{ 2, 6},
{ 3, 9}
});
var series = new[] { sm1, sm2, sm3 };
var sum = series.Zip((k, varr) => k * varr.Sum());
var zipNCursor = sum.GetCursor();
var movedFirst = zipNCursor.MoveFirst();
Assert.IsTrue(movedFirst);
Assert.AreEqual((2 + 4 + 6) * 2, zipNCursor.CurrentValue);
var movedLast = zipNCursor.MoveLast();
Assert.IsTrue(movedLast);
Assert.AreEqual((2 + 4 + 6) * 2, zipNCursor.CurrentValue);
}
示例2: CouldZipLagSeries
public void CouldZipLagSeries() {
var sm = new SortedMap<DateTime, double>();
var count = 10000000;
for (int i = 0; i < count; i++) {
sm.Add(DateTime.UtcNow.Date.AddSeconds(i), i);
}
// slow implementation
var sw = new Stopwatch();
sw.Start();
var zipLag = sm.ZipLag(1, (cur, prev) => cur + prev); //.ToSortedMap();
var c = 1;
foreach (var zl in zipLag) {
if (c + (c - 1) != zl.Value) {
throw new ApplicationException();
}
c++;
}
sw.Stop();
Console.WriteLine($"Final c: {c}");
Console.WriteLine("ZipLag, elapsed: {0}, ops: {1}", sw.ElapsedMilliseconds, (int)((double)count / (sw.ElapsedMilliseconds / 1000.0)));
}
示例3: CouldLagSeries
public void CouldLagSeries() {
var sm = new SortedMap<double, double>();
var count = 1000000;
for (int i = 0; i < count; i++) {
sm.Add(i, i);
}
// slow implementation
var sw = new Stopwatch();
sw.Start();
var lag = sm.Lag(1);//.ToSortedMap();
var c = 1;
foreach (var zl in lag) {
if (c - 1 != zl.Value) {
throw new ApplicationException();
}
c++;
}
sw.Stop();
Console.WriteLine($"Final c: {c}");
Console.WriteLine("ZipLag, elapsed: {0}, ops: {1}", sw.ElapsedMilliseconds, (int)((double)count / (sw.ElapsedMilliseconds / 1000.0)));
var repeated = lag.Repeat();
for (int i = 1; i < 1000; i++)
{
double v;
Assert.IsTrue(repeated.TryGetValue(i+1.5, out v));
Assert.AreEqual(i, v);
}
}
示例4: CouldCalculateSMAInRealTime
public void CouldCalculateSMAInRealTime() {
var sm = new SortedMap<int, double>();
Task.Run(async () => {
for (int i = 0; i < 20; i++) {
sm.Add(i, i);
}
await Task.Delay(100);
for (int i = 20; i < 100; i++) {
await Task.Delay(1); // 15 msec
sm.Add(i, i);
}
sm.IsMutable = false;
});
var sma = sm.SMA(10, true);
var c = sma.GetCursor();
while (c.MoveNext(CancellationToken.None).Result) {
Console.WriteLine("Key: {0}, value: {1}", c.CurrentKey, c.CurrentValue);
}
}
示例5: IncrementMap
/// <summary>
/// Very straighforward batch operation for testing
/// </summary>
public IReadOnlyOrderedMap<DateTime, double> IncrementMap(IReadOnlyOrderedMap<DateTime, double> batch) {
var sm = new SortedMap<DateTime, double>();
foreach (var kvp in batch) {
sm.Add(kvp.Key, kvp.Value + 1.0);
}
return sm;
}
示例6: MultiplyMap
public IReadOnlyOrderedMap<DateTime, double> MultiplyMap(IReadOnlyOrderedMap<DateTime, double> batch) {
var sm = new SortedMap<DateTime, double>();
foreach (var kvp in batch) {
sm.Add(kvp.Key, kvp.Value * 10.0);
}
return sm;
}
示例7: CouldRepeatMapSeries
public void CouldRepeatMapSeries() {
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 * 2 + 1 + 1;
}
OptimizationSettings.CombineFilterMapDelegates = false;
var sw = new Stopwatch();
sw.Start();
var sum = (sm.Repeat().Map(x => x + 1.0).Repeat().Map(x => x + 1.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)));
}
示例8: 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)));
}
示例9: 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);
}
示例10: UpdateEventIsTriggered
public void UpdateEventIsTriggered() {
var sm = new SortedMap<DateTime, double>();
(sm as IObservableEvents<DateTime, double>).OnNext += (kvp) => {
Console.WriteLine("Added {0} : {1}", kvp.Key, kvp.Value);
};
sm.Add(DateTime.UtcNow.Date.AddSeconds(0), 0);
}
示例11: ZipNFromLogoAndReadmeRepeatCouldMoveCursorCorrectly
public void ZipNFromLogoAndReadmeRepeatCouldMoveCursorCorrectly() {
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);
var cursor = sum.GetCursor();
Assert.AreEqual(32, sum[3]);
Assert.AreEqual(54, sum[5]);
Assert.IsFalse(cursor.MoveAt(1, Lookup.EQ));
Assert.IsTrue(cursor.MoveAt(1, Lookup.GE));
Assert.AreEqual(3, cursor.CurrentKey);
Assert.AreEqual(32, cursor.CurrentValue);
// move forward
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(3, cursor.CurrentKey);
Assert.AreEqual(32, cursor.CurrentValue);
// async moves
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
lower.Add(6, 60);
t.Wait();
Assert.IsTrue(moved);
Assert.AreEqual(6, cursor.CurrentKey);
Assert.AreEqual(4 + 60, 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);
}
示例12: UpdateEventIsTriggered
public void UpdateEventIsTriggered() {
var sm = new SortedMap<DateTime, double>();
(sm as IUpdateable<DateTime, double>).OnData += (s, x) => {
Console.WriteLine("Added {0} : {1}", x.Key,
x.Value);
};
sm.Add(DateTime.UtcNow.Date.AddSeconds(0), 0);
}
示例13: readFromSortedMap
public override void readFromSortedMap(SortedMap<Integer, String> sortedAreaCodeMap)
{
numOfEntries = sortedAreaCodeMap.size();
phoneNumberPrefixes = new int[numOfEntries];
descriptions = new String[numOfEntries];
int index = 0;
foreach (int prefix in sortedAreaCodeMap.keySet()) {
phoneNumberPrefixes[index++] = prefix;
possibleLengths.add((int) Math.log10(prefix) + 1);
}
sortedAreaCodeMap.values().toArray(descriptions);
}
示例14: 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));
}
示例15: 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);
}