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


C# ConcurrentDictionary.GetOrDefault方法代码示例

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


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

示例1: IndexDocuments


//.........这里部分代码省略.........
                    allReferenceEtags.Enqueue(CurrentIndexingScope.Current.ReferencesEtags);
                    allReferencedDocs.Enqueue(CurrentIndexingScope.Current.ReferencedDocuments);
                }
            });

            performanceStats.Add(new ParallelPerformanceStats
            {
                NumberOfThreads = parallelOperations.Count,
                DurationMs = (long)(SystemTime.UtcNow - parallelProcessingStart).TotalMilliseconds,
                BatchedOperations = parallelOperations.ToList()
            });

            var updateDocumentReferencesDuration = new Stopwatch();
            using (StopwatchScope.For(updateDocumentReferencesDuration))
            {
                UpdateDocumentReferences(actions, allReferencedDocs, allReferenceEtags);
            }
            performanceStats.Add(PerformanceStats.From(IndexingOperation.UpdateDocumentReferences, updateDocumentReferencesDuration.ElapsedMilliseconds));

            var changed = allState.SelectMany(x => x.Item1).Concat(deleted.Keys)
                    .Distinct()
                    .ToList();

            var stats = new IndexingWorkStats(allState.Select(x => x.Item2));
            var reduceKeyStats = allState.SelectMany(x => x.Item3)
                                         .GroupBy(x => x.Key)
                                         .Select(g => new { g.Key, Count = g.Sum(x => x.Value) })
                                         .ToList();

            var reduceKeyToCount = new ConcurrentDictionary<string, int>();
            foreach (var singleDeleted in deleted)
            {
                var reduceKey = singleDeleted.Key.ReduceKey;
                reduceKeyToCount[reduceKey] = reduceKeyToCount.GetOrDefault(reduceKey) + singleDeleted.Value;
            }

            BackgroundTaskExecuter.Instance.ExecuteAllBuffered(context, reduceKeyStats, enumerator => context.TransactionalStorage.Batch(accessor =>
            {
                while (enumerator.MoveNext())
                {
                    var reduceKeyStat = enumerator.Current;
                    var value = 0;
                    reduceKeyToCount.TryRemove(reduceKeyStat.Key, out value);

                    var changeValue = reduceKeyStat.Count - value;
                    if (changeValue == 0)
                    {
                        // nothing to change
                        continue;
                    }

                    accessor.MapReduce.IncrementReduceKeyCounter(indexId, reduceKeyStat.Key, changeValue);
                }
            }));

            foreach (var keyValuePair in reduceKeyToCount)
            {
                // those are the remaining keys that weren't used,
                // reduce keys that were replaced
                actions.MapReduce.IncrementReduceKeyCounter(indexId, keyValuePair.Key, -keyValuePair.Value);
            }

            actions.General.MaybePulseTransaction();

            var parallelReductionOperations = new ConcurrentQueue<ParallelBatchStats>();
            var parallelReductionStart = SystemTime.UtcNow;
开发者ID:IdanHaim,项目名称:ravendb,代码行数:67,代码来源:MapReduceIndex.cs


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