Soenneker.Sets.Concurrent.Bounded
4.0.34
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Sets.Concurrent.Bounded --version 4.0.34
NuGet\Install-Package Soenneker.Sets.Concurrent.Bounded -Version 4.0.34
<PackageReference Include="Soenneker.Sets.Concurrent.Bounded" Version="4.0.34" />
<PackageVersion Include="Soenneker.Sets.Concurrent.Bounded" Version="4.0.34" />
<PackageReference Include="Soenneker.Sets.Concurrent.Bounded" />
paket add Soenneker.Sets.Concurrent.Bounded --version 4.0.34
#r "nuget: Soenneker.Sets.Concurrent.Bounded, 4.0.34"
#:package Soenneker.Sets.Concurrent.Bounded@4.0.34
#addin nuget:?package=Soenneker.Sets.Concurrent.Bounded&version=4.0.34
#tool nuget:?package=Soenneker.Sets.Concurrent.Bounded&version=4.0.34
Soenneker.Sets.Concurrent.Bounded
A high-performance bounded concurrent set for .NET
Soenneker.Sets.Concurrent.Bounded provides a thread-safe concurrent set with an approximate maximum size.
It behaves similarly to a ConcurrentDictionary-backed set but automatically evicts older entries when the set grows beyond a configured limit.
Designed for high-throughput workloads where preventing unbounded memory growth is more important than strict eviction guarantees.
Typical uses include:
- deduplication caches
- request ID tracking
- preventing duplicate messages
- bounded concurrent caches
- rate limiting helpers
- abuse protection
- event stream deduplication
Installation
dotnet add package Soenneker.Sets.Concurrent.Bounded
Why this library exists
The .NET ecosystem lacks a simple bounded concurrent set.
Existing options have tradeoffs:
| Collection | Problem |
|---|---|
ConcurrentDictionary |
Unbounded growth |
HashSet |
Not thread-safe |
MemoryCache |
Heavy for simple dedupe use cases |
| LRU caches | Often require locks or background eviction |
BoundedConcurrentSet provides a lightweight alternative optimized for:
- high concurrency
- predictable memory usage
- low allocation
- minimal locking
Features
✔ High-throughput concurrent operations ✔ Approximate size bounding ✔ Opportunistic eviction of older entries ✔ Lock-minimized design ✔ Low allocation footprint ✔ Safe for heavy multi-threaded workloads
Example
using Soenneker.Sets.Concurrent.Bounded;
var set = new BoundedConcurrentSet<string>(maxSize: 1000);
set.TryAdd("alpha");
set.TryAdd("beta");
bool exists = set.Contains("alpha");
set.TryRemove("beta");
string[] snapshot = set.ToArray();
Configuration
var set = new BoundedConcurrentSet<string>(
maxSize: 1000,
capacityHint: 1000,
trimBatchSize: 64,
trimStartOveragePercent: 5
);
| Parameter | Description |
|---|---|
maxSize |
Target maximum number of elements |
capacityHint |
Initial capacity hint for the dictionary |
trimBatchSize |
Number of eviction attempts per trim cycle |
trimStartOveragePercent |
Allowed overage before trimming begins |
Performance Characteristics
| Operation | Complexity |
|---|---|
TryAdd |
O(1) average |
Contains |
O(1) |
TryRemove |
O(1) |
Eviction work is bounded per call, preventing long latency spikes.
Internally the structure uses:
- concurrent dictionary indexing
- opportunistic FIFO-like eviction
- generation tokens to avoid stale scans
- atomic counters for approximate size tracking
When to use this
Use this collection when you need:
- a bounded concurrent set
- deduplication tracking
- a lightweight concurrent cache
- to prevent unbounded memory growth
Good examples:
- deduplicating phone numbers
- tracking recent request IDs
- preventing duplicate events
- guarding against repeated API calls
Thread Safety
All operations are fully thread-safe.
The implementation is designed for high-concurrency environments and does not require external locking.
| 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.20)
- Soenneker.Atomics.ValueInts (>= 4.0.23)
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 |