本文整理汇总了C#中SortedMap.Add方法的典型用法代码示例。如果您正苦于以下问题:C# SortedMap.Add方法的具体用法?C# SortedMap.Add怎么用?C# SortedMap.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedMap
的用法示例。
在下文中一共展示了SortedMap.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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)));
}
示例5: 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)));
}
示例6: 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)));
}
示例7: 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);
}
}
示例8: 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);
}
示例9: 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);
}
示例10: 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);
}
示例11: 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));
}
示例12: CouldCalculateIncompleteMovingAverage
public void CouldCalculateIncompleteMovingAverage() {
var sm = new SortedMap<int, double>();
for (int i = 0; i < 20; i++) {
sm.Add(i, i);
}
var sma = sm.SMA(2, true).ToSortedMap();
var c = 0;
foreach (var kvp in sma) {
if (c == 0) {
Assert.AreEqual(c, kvp.Value);
} else {
Assert.AreEqual(0.5 * (c + (double)(c - 1)), kvp.Value);
}
c++;
}
}
示例13: CouldCalculateComplexGraph
public void CouldCalculateComplexGraph() {
// TODO! need real complex data to test properly
var sm = new SortedMap<DateTime, double>();
var dataTask = Task.Run(async () => {
for (int i = 0; i < 1000; i++) {
sm.Add(DateTime.Today.AddSeconds(i), i+10000);
await Task.Delay(25);
}
sm.IsMutable = false;
});
Thread.Sleep(50);
var closeSeries = sm;
var baseLeverage = 1.0;
var sma = closeSeries.SMA(20, true);
var deviation = sma / closeSeries - 1.0;
var leverage = (baseLeverage * (-(5.0 * (deviation.Map(x => Math.Abs(x)))) + 1.0));
var smaSignal = deviation.Map(x => (double)(Math.Sign(x)));
var smaPositionMultiple = ((smaSignal * leverage).Map(x => 0.25 * (Math.Round(x / 0.25))));
var smaPositionMultipleMap = smaPositionMultiple.ToSortedMap();
var traderTask = Task.Run(async () => {
var positionCursor = smaPositionMultiple.GetCursor();
while (await positionCursor.MoveNext(CancellationToken.None)) //
{
await Task.Delay(15);
Console.WriteLine("Time: {0}, position: {1}", positionCursor.CurrentKey, positionCursor.CurrentValue);
}
});
dataTask.Wait();
traderTask.Wait();
}
示例14: CouldMoveNextWithoutBatching
public void CouldMoveNextWithoutBatching() {
var sm = new SortedMap<DateTime, double>();
var count = 1000;
for (int i = 0; i < count; i++) {
sm.Add(DateTime.UtcNow.Date.AddSeconds(i), i);
}
sm.IsMutable = false;
var bmvc = new BatchMapValuesCursor<DateTime, double, double>(sm.GetCursor, (v) => v + 1.0);
var c = 0;
while (c < 500 && bmvc.MoveNext()) {
Assert.AreEqual(c + 1.0, bmvc.CurrentValue);
c++;
}
while (bmvc.MoveNext(CancellationToken.None).Result) { // Setting IsMutable to false allows us to skip this check: c < 1000 &&
Assert.AreEqual(c + 1.0, bmvc.CurrentValue);
c++;
}
Assert.AreEqual(count, c);
}
示例15: CouldMovePreviousWithoutBatching
public void CouldMovePreviousWithoutBatching() {
var sm = new SortedMap<DateTime, double>();
var count = 1000;
for (int i = 0; i < count; i++) {
sm.Add(DateTime.UtcNow.Date.AddSeconds(i), i);
}
sm.IsMutable = false;
var bmvc = new BatchMapValuesCursor<DateTime, double, double>(sm.GetCursor, (v) => v + 1.0);
var c = 0;
while (c < 500 && bmvc.MoveNext()) {
Assert.AreEqual(c + 1.0, bmvc.CurrentValue);
c++;
}
c--;
while (bmvc.MovePrevious()) {
c--;
Assert.AreEqual(c + 1.0, bmvc.CurrentValue);
}
Assert.AreEqual(0, c);
}