当前位置: 首页>>代码示例>>C#>>正文


C# SortedMap.ZipLag方法代码示例

本文整理汇总了C#中SortedMap.ZipLag方法的典型用法代码示例。如果您正苦于以下问题:C# SortedMap.ZipLag方法的具体用法?C# SortedMap.ZipLag怎么用?C# SortedMap.ZipLag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortedMap的用法示例。


在下文中一共展示了SortedMap.ZipLag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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)));

        }
开发者ID:b-e-n-j,项目名称:Spreads,代码行数:25,代码来源:MiscCursorsTests.cs

示例2: CouldCloneZipLagSeries

        public void CouldCloneZipLagSeries() {
            

            var count = 1000;
            var sm = new SortedMap<int, double>();
            for (int i = 0; i < count; i++) {
                sm.Add(i, i);
            }

            // slow implementation
            var sw = new Stopwatch();
            sw.Start();
            var zipLag = sm.ZipLag(1, (cur, prev) => cur + prev); //.ToSortedMap();

            var zc = zipLag.GetCursor();
            zc.MoveNext();
            var zc2 = zc.Clone();
            Assert.AreEqual(zc.CurrentKey, zc2.CurrentKey);
            zc.MoveNext();
            zc2.MoveNext();
            Assert.AreEqual(zc.CurrentKey, zc2.CurrentKey);
            zc.MovePrevious();
            zc2.MovePrevious();
            Assert.AreEqual(zc.CurrentKey, zc2.CurrentKey);


            for (int i = 1; i < count; i++)
            {
                var expected = i + i - 1;
                double actual;
                var ok = zc.TryGetValue(i, out actual);
                Assert.AreEqual(expected, actual);
            }

            var sm2 = new SortedMap<int, double>();
            var zc3 = sm2.ZipLag(1, (cur, prev) => cur + prev).GetCursor();

            var t = Task.Run(async () =>
            {
                var c = 1; // first key is missing because we cannot create state at it
                while (await zc3.MoveNext(CancellationToken.None))
                {
                    var expected = c + c - 1;
                    Assert.AreEqual(expected, zc3.CurrentValue);
                    c++;
                }
            });

            for (int i = 0; i < count; i++) {
                sm2.Add(i, i);
            }
            sm2.IsMutable = false; // without it MoveNextAsync will wait forever
            t.Wait();
        }
开发者ID:b-e-n-j,项目名称:Spreads,代码行数:54,代码来源:MiscCursorsTests.cs


注:本文中的SortedMap.ZipLag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。