Soenneker.Sets.Concurrent.Bounded
4.0.46
Prefix Reserved
dotnet add package Soenneker.Sets.Concurrent.Bounded --version 4.0.46
NuGet\Install-Package Soenneker.Sets.Concurrent.Bounded -Version 4.0.46
<PackageReference Include="Soenneker.Sets.Concurrent.Bounded" Version="4.0.46" />
<PackageVersion Include="Soenneker.Sets.Concurrent.Bounded" Version="4.0.46" />
<PackageReference Include="Soenneker.Sets.Concurrent.Bounded" />
paket add Soenneker.Sets.Concurrent.Bounded --version 4.0.46
#r "nuget: Soenneker.Sets.Concurrent.Bounded, 4.0.46"
#:package Soenneker.Sets.Concurrent.Bounded@4.0.46
#addin nuget:?package=Soenneker.Sets.Concurrent.Bounded&version=4.0.46
#tool nuget:?package=Soenneker.Sets.Concurrent.Bounded&version=4.0.46
Soenneker.Sets.Concurrent.Bounded
A concurrent set with bounded-work, best-effort FIFO eviction after its configured size threshold is exceeded.
Installation
dotnet add package Soenneker.Sets.Concurrent.Bounded
Usage
using Soenneker.Sets.Concurrent.Bounded;
var seenRequestIds = new BoundedConcurrentSet<string>(
maxSize: 10_000,
comparer: StringComparer.Ordinal);
if (!seenRequestIds.TryAdd(requestId))
{
// The value was already present at the time of the add attempt.
return;
}
bool isPresent = seenRequestIds.Contains(requestId);
bool removed = seenRequestIds.TryRemove(requestId);
string[] snapshot = seenRequestIds.ToArray();
TryAdd returns false for an existing value. A successful addition can still be evicted later by another add. Contains, TryRemove, and enumeration are thread-safe, but a result is only a point-in-time observation while other threads mutate the set.
Bounding and eviction
This is not a strict-capacity collection. With the default five-percent overage, trimming begins only after the approximate count exceeds maxSize + ceil(maxSize * 0.05). Concurrent additions and the per-call work budget can produce a larger temporary overage.
Trimming examines insertion records in approximate FIFO order and removes generation-matched live entries until the count reaches maxSize or the work budget is exhausted. Reading an entry does not refresh it, so this is not LRU behavior.
Removed and re-added values use new generation tokens. Stale queue records cannot remove the newer generation.
ApproxCount is maintained with atomic updates and occasionally resynchronized from the dictionary. Use it for telemetry and heuristics, not for check-then-act correctness. Values is a live concurrent view; ToArray creates a snapshot of keys observed during that call.
Tuning
var set = new BoundedConcurrentSet<string>(
maxSize: 10_000,
capacityHint: 10_000,
trimBatchSize: 64,
trimStartOveragePercent: 5,
maxTrimWorkPerCall: 4_096,
resyncAfterNoProgress: 8,
queueOverageFactor: 4,
comparer: StringComparer.Ordinal);
capacityHintsets the dictionary's initial capacity; it is not another size limit.trimBatchSizeis the minimum eviction work budget when trimming begins.trimStartOveragePercentcontrols how far abovemaxSizethe approximate count may grow before an add triggers trimming. Use0to start immediately abovemaxSize.maxTrimWorkPerCallcaps eviction work performed by one operation.resyncAfterNoProgresscontrols how many no-removal trim attempts occur before the approximate count is corrected from the dictionary. Use0to disable that correction trigger.queueOverageFactorstarts bounded stale-record cleanup when the insertion queue estimate exceedsmaxSize * factor.comparercontrols value equality in the underlying concurrent dictionary.
Use this set when temporary overage and best-effort eviction are acceptable, such as telemetry suppression or bounded deduplication hints. Do not use it as an authorization boundary, durable idempotency store, exact rate limiter, or any other control where eviction timing and strict capacity are correctness requirements.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Soenneker.Atomics.Longs (>= 4.0.27)
- Soenneker.Atomics.ValueInts (>= 4.0.30)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Sets.Concurrent.Bounded:
| Package | Downloads |
|---|---|
|
Soenneker.Deduplication.Bounded
A thread-safe high-performance bounded size deduplication utility for .NET. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.46 | 23 | 9/24/2026 |
| 4.0.45 | 25 | 9/24/2026 |
| 4.0.44 | 211 | 9/15/2026 |
| 4.0.43 | 92 | 9/15/2026 |
| 4.0.42 | 285 | 9/12/2026 |
| 4.0.41 | 124 | 9/12/2026 |
| 4.0.38 | 556 | 8/30/2026 |
| 4.0.37 | 101 | 8/30/2026 |
| 4.0.36 | 148 | 8/30/2026 |
| 4.0.35 | 99 | 8/29/2026 |
| 4.0.34 | 713 | 7/28/2026 |
| 4.0.33 | 104 | 7/28/2026 |
| 4.0.32 | 112 | 7/27/2026 |
| 4.0.31 | 377 | 7/17/2026 |
| 4.0.30 | 170 | 7/16/2026 |
| 4.0.29 | 161 | 7/16/2026 |
| 4.0.28 | 474 | 6/19/2026 |
| 4.0.27 | 119 | 6/19/2026 |
| 4.0.26 | 120 | 6/19/2026 |
| 4.0.25 | 494 | 6/6/2026 |