本文整理汇总了C#中ConcurrentSet类的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentSet类的具体用法?C# ConcurrentSet怎么用?C# ConcurrentSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConcurrentSet类属于命名空间,在下文中一共展示了ConcurrentSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: should_test_that_an_item_is_contained
public void should_test_that_an_item_is_contained()
{
var setToRemoveFrom = new ConcurrentSet<int>(Enumerable.Range(1, 5));
setToRemoveFrom.Contains(3).ShouldBeTrue();
setToRemoveFrom.Contains(7).ShouldBeFalse();
}
示例2: CreateProjectMapAsync
private async Task<ProjectMap> CreateProjectMapAsync(ConcurrentSet<SymbolAndProjectId> symbols)
{
using (Logger.LogBlock(FunctionId.FindReference_CreateProjectMapAsync, _cancellationToken))
{
var projectMap = new ProjectMap();
var scope = _documents?.Select(d => d.Project).ToImmutableHashSet();
foreach (var symbolAndProjectId in symbols)
{
foreach (var finder in _finders)
{
_cancellationToken.ThrowIfCancellationRequested();
var projects = await finder.DetermineProjectsToSearchAsync(symbolAndProjectId.Symbol, _solution, scope, _cancellationToken).ConfigureAwait(false);
foreach (var project in projects.Distinct().WhereNotNull())
{
if (scope == null || scope.Contains(project))
{
projectMap.Add(project, (symbolAndProjectId, finder));
}
}
}
}
Contract.ThrowIfTrue(projectMap.Any(kvp => kvp.Value.Count != kvp.Value.ToSet().Count));
return projectMap;
}
}
示例3: HandleReduceForIndex
protected void HandleReduceForIndex(IndexToWorkOn indexToWorkOn)
{
var viewGenerator = context.IndexDefinitionStorage.GetViewGenerator(indexToWorkOn.IndexId);
if (viewGenerator == null)
return;
bool operationCanceled = false;
var itemsToDelete = new ConcurrentSet<object>();
IList<ReduceTypePerKey> mappedResultsInfo = null;
transactionalStorage.Batch(actions =>
{
mappedResultsInfo = actions.MapReduce.GetReduceTypesPerKeys(indexToWorkOn.IndexId,
context.CurrentNumberOfItemsToReduceInSingleBatch,
context.NumberOfItemsToExecuteReduceInSingleStep).ToList();
});
var singleStepReduceKeys = mappedResultsInfo.Where(x => x.OperationTypeToPerform == ReduceType.SingleStep).Select(x => x.ReduceKey).ToArray();
var multiStepsReduceKeys = mappedResultsInfo.Where(x => x.OperationTypeToPerform == ReduceType.MultiStep).Select(x => x.ReduceKey).ToArray();
currentlyProcessedIndexes.TryAdd(indexToWorkOn.IndexId, indexToWorkOn.Index);
try
{
if (singleStepReduceKeys.Length > 0)
{
Log.Debug("SingleStep reduce for keys: {0}",singleStepReduceKeys.Select(x => x + ","));
SingleStepReduce(indexToWorkOn, singleStepReduceKeys, viewGenerator, itemsToDelete);
}
if (multiStepsReduceKeys.Length > 0)
{
Log.Debug("MultiStep reduce for keys: {0}", singleStepReduceKeys.Select(x => x + ","));
MultiStepReduce(indexToWorkOn, multiStepsReduceKeys, viewGenerator, itemsToDelete);
}
}
catch (OperationCanceledException)
{
operationCanceled = true;
}
finally
{
if (operationCanceled == false)
{
// whatever we succeeded in indexing or not, we have to update this
// because otherwise we keep trying to re-index failed mapped results
transactionalStorage.Batch(actions =>
{
var latest = actions.MapReduce.DeleteScheduledReduction(itemsToDelete);
if (latest == null)
return;
actions.Indexing.UpdateLastReduced(indexToWorkOn.Index.indexId, latest.Etag, latest.Timestamp);
});
}
Index _;
currentlyProcessedIndexes.TryRemove(indexToWorkOn.IndexId, out _);
}
}
示例4: RabbitMqPollingNode
/// <summary>
/// Create a work item queue that will try to pull items from a named RabbitMQ endpoint
/// </summary>
/// <param name="endpoint">Destination endpoint to pull messages from</param>
/// <param name="messagingBase">RabbitMQ connection provider</param>
/// <param name="sleeper">Sleeper to rate limit polling</param>
public RabbitMqPollingNode(IRoutingEndpoint endpoint,
IMessagingBase messagingBase, ISleepWrapper sleeper)
{
_endpoint = endpoint.ToString();
_messagingBase = messagingBase;
_sleeper = sleeper;
_boundMessageTypes = new ConcurrentSet<Type>();
}
示例5: should_add_an_item
public void should_add_an_item()
{
var setToRemoveFrom = new ConcurrentSet<int>(Enumerable.Range(1, 5));
setToRemoveFrom.Add(6);
setToRemoveFrom.ShouldEqual(new[] { 1, 2, 3, 4, 5, 6 });
}
示例6: should_clear_itself
public void should_clear_itself()
{
var setToClear = new ConcurrentSet<int>(Enumerable.Range(1, 5));
setToClear.Clear();
setToClear.Count.ShouldEqual(0);
}
示例7: should_remove_an_item
public void should_remove_an_item()
{
var setToRemoveFrom = new ConcurrentSet<int>(Enumerable.Range(1, 5));
setToRemoveFrom.Remove(3);
setToRemoveFrom.ShouldEqual(new[] { 1, 2, 4, 5 });
}
示例8: WatcherInfo
public WatcherInfo(FileSystemWatcher watcher, Boolean isDirectory)
: this()
{
Watcher = watcher;
if (isDirectory)
WatchedFiles = new ConcurrentSet<String>();
}
示例9: LocalQueuePollingNode
/// <summary>
/// Create a local polling node.
/// <para>You should not use this yourself. Use:</para>
/// <para>MessagingSystem.Configure.WithLocalQueue(...);</para>
/// and receive messages as normal.
/// </summary>
public LocalQueuePollingNode(string dispatchPath, string incomingPath,
IMessageSerialiser serialiser, ISleepWrapper sleeper)
{
_dispatchPath = dispatchPath;
_incomingPath = incomingPath;
_serialiser = serialiser;
_sleeper = sleeper;
_boundMessageTypes = new ConcurrentSet<Type>();
}
示例10: should_copy_itself_to_an_array
public void should_copy_itself_to_an_array()
{
var setToCopy = new ConcurrentSet<int>(Enumerable.Range(1, 5));
var destinationArray = new int[5];
setToCopy.CopyTo(destinationArray, 0);
destinationArray.ShouldEqual(new[] { 1, 2, 3, 4, 5 });
}
示例11: GetItemsToReduceParams
public GetItemsToReduceParams(string index, IEnumerable<string> reduceKeys, int level, bool loadData, ConcurrentSet<object> itemsToDelete)
{
Index = index;
Level = level;
LoadData = loadData;
ItemsToDelete = itemsToDelete;
ItemsAlreadySeen = new HashSet<Tuple<string, int>>();
ReduceKeys = new HashSet<string>(reduceKeys);
}
示例12: RunAsync
public async Task RunAsync() {
Console.WriteLine(DateTime.Now);
const int kMessagesPerWorker = 200000;
var sink = courierFacades[0];
var senders = courierFacades.Skip(1).ToArray();
var counter = kMessagesPerWorker * senders.Length;
var doneSignal = new AsyncLatch();
int upCounter = 0;
var set = new ConcurrentSet<int>();
sink.InboundMessageRouter.RegisterHandler<string>(
x => {
set.AddOrThrow(int.Parse(x.Body));
var newCounter = Interlocked.Decrement(ref counter);
Interlocked.Increment(ref upCounter);
if (upCounter % 500 == 0)
Console.WriteLine(newCounter + " " + upCounter);
if (newCounter == 0) {
doneSignal.Set();
}
return Task.FromResult(false);
});
var sync = new AsyncCountdownLatch(senders.Length);
var senderTasks = senders.Select((s, id) => Go(async () => {
await s.PeerTable.GetOrAdd(sink.Identity.Id).WaitForDiscoveryAsync().ConfigureAwait(false);
sync.Signal();
await sync.WaitAsync().ConfigureAwait(false);
Console.WriteLine("Sink discovered: " + DateTime.Now);
const int kBatchFactor = 1;
for (var batch = 0; batch < kBatchFactor; batch++) {
var batchSize = kMessagesPerWorker / kBatchFactor;
await Task.WhenAll(Util.Generate(
batchSize,
i => s.Messenger.SendReliableAsync(
"" + (batch * batchSize + i + id * kMessagesPerWorker),
sink.Identity.Id))
).ConfigureAwait(false);
}
Console.WriteLine("Worker Done: " + DateTime.Now);
}));
await Task.WhenAll(senderTasks).ConfigureAwait(false);
Console.WriteLine("Senders Done: " + DateTime.Now);
await doneSignal.WaitAsync().ConfigureAwait(false);
Console.WriteLine("Done Signalled: " + DateTime.Now);
AssertCollectionDeepEquals(set, new ConcurrentSet<int>(Enumerable.Range(0, kMessagesPerWorker * senders.Length)));
while (true) {
GC.Collect();
}
}
示例13: CompilationWithAnalyzers
/// <summary>
/// Creates a new compilation by attaching diagnostic analyzers to an existing compilation.
/// </summary>
/// <param name="compilation">The original compilation.</param>
/// <param name="analyzers">The set of analyzers to include in future analyses.</param>
/// <param name="options">Options that are passed to analyzers.</param>
/// <param name="cancellationToken">A cancellation token that can be used to abort analysis.</param>
public CompilationWithAnalyzers(Compilation compilation, ImmutableArray<DiagnosticAnalyzer> analyzers, AnalyzerOptions options, CancellationToken cancellationToken)
{
if (compilation == null)
{
throw new ArgumentNullException(nameof(compilation));
}
VerifyAnalyzersArgument(analyzers);
_cancellationToken = cancellationToken;
_exceptionDiagnostics = new ConcurrentSet<Diagnostic>();
_driver = AnalyzerDriver.Create(compilation, analyzers, options, AnalyzerManager.Instance, AddExceptionDiagnostic, false, out _compilation, _cancellationToken);
}
示例14: CodeLensFindReferencesProgress
public CodeLensFindReferencesProgress(
ISymbol queriedDefinition,
SyntaxNode queriedNode,
int searchCap,
CancellationToken cancellationToken)
{
_queriedSymbol = queriedDefinition;
_queriedNode = queriedNode;
_aggregateCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
_locations = new ConcurrentSet<Location>();
SearchCap = searchCap;
}
示例15: CreateProjectMapAsync
private async Task<ConcurrentDictionary<Project, ConcurrentQueue<ValueTuple<SymbolAndProjectId, IReferenceFinder>>>> CreateProjectMapAsync(
ConcurrentSet<SymbolAndProjectId> symbols)
{
using (Logger.LogBlock(FunctionId.FindReference_CreateProjectMapAsync, _cancellationToken))
{
Func<Project, ConcurrentQueue<ValueTuple<SymbolAndProjectId, IReferenceFinder>>> createQueue =
p => new ConcurrentQueue<ValueTuple<SymbolAndProjectId, IReferenceFinder>>();
var projectMap = new ConcurrentDictionary<Project, ConcurrentQueue<ValueTuple<SymbolAndProjectId, IReferenceFinder>>>();
#if PARALLEL
Roslyn.Utilities.TaskExtensions.RethrowIncorrectAggregateExceptions(cancellationToken, () =>
{
symbols.AsParallel().WithCancellation(cancellationToken).ForAll(s =>
{
finders.AsParallel().WithCancellation(cancellationToken).ForAll(f =>
{
var projects = f.DetermineProjectsToSearch(s, solution, cancellationToken) ?? SpecializedCollections.EmptyEnumerable<Project>();
foreach (var project in projects.Distinct())
{
projectMap.GetOrAdd(project, createQueue).Enqueue(ValueTuple.Create(s, f));
}
});
});
});
#else
var scope = _documents != null ? _documents.Select(d => d.Project).ToImmutableHashSet() : null;
foreach (var s in symbols)
{
foreach (var f in _finders)
{
_cancellationToken.ThrowIfCancellationRequested();
var projects = await f.DetermineProjectsToSearchAsync(s.Symbol, _solution, scope, _cancellationToken).ConfigureAwait(false);
foreach (var project in projects.Distinct().WhereNotNull())
{
if (scope == null || scope.Contains(project))
{
projectMap.GetOrAdd(project, createQueue).Enqueue(ValueTuple.Create(s, f));
}
}
}
}
#endif
Contract.ThrowIfTrue(projectMap.Any(kvp => kvp.Value.Count != kvp.Value.ToSet().Count));
return projectMap;
}
}