![]() |
VOOZH | about |
dotnet add package Gapotchenko.FX.Collections --version 2026.7.2
NuGet\Install-Package Gapotchenko.FX.Collections -Version 2026.7.2
<PackageReference Include="Gapotchenko.FX.Collections" Version="2026.7.2" />
<PackageVersion Include="Gapotchenko.FX.Collections" Version="2026.7.2" />Directory.Packages.props
<PackageReference Include="Gapotchenko.FX.Collections" />Project file
paket add Gapotchenko.FX.Collections --version 2026.7.2
#r "nuget: Gapotchenko.FX.Collections, 2026.7.2"
#:package Gapotchenko.FX.Collections@2026.7.2
#addin nuget:?package=Gapotchenko.FX.Collections&version=2026.7.2Install as a Cake Addin
#tool nuget:?package=Gapotchenko.FX.Collections&version=2026.7.2Install as a Cake Tool
The module was started by borrowing an implementation of ConcurrentHashSet<T> from Mr. Bar Arnon.
Other than that, the module provides polyfills for missing functionality in .NET.
ConcurrentHashSet<T> provided by Gapotchenko.FX.Collections is a thread-safe implementation of HashSet<T>.
AssociativeArray<TKey, TValue> provided by Gapotchenko.FX.Collections is a drop-in replacement for Dictionary<TKey, TValue> that can handle null keys.
Dictionary<TKey, TValue> cannot work with null keys and throws ArgumentNullException whenever a null key is encountered.
AssociativeArray<TKey, TValue> solves that by supporting the full space of keys without opinionated exclusions.
Deque<T> provided by Gapotchenko.FX.Collections is a linear collection that supports element insertion and removal at both ends with O(1) algorithmic complexity.
Deque<T> can be seen as a List<T>, but in contrast to the List<T>, both ends of the collection support efficient addition and removal of elements.
A concept of a construction kit provided by Gapotchenko.FX.Collections module allows you to quickly and reliably build customized collection primitives.
<details> <summary>More information</summary>
For example, let's imagine that we need to build a custom implementation of System.Collections.Generic.ISet<T> collection.
In order to do that, we need to implement a plethora of methods such as UnionWith, IntersectWith, ExceptWith and others just to begin with.
It gets complicated and nuanced quickly, while all we want is to build a simple custom ISet<T> implementation.
This is where the concept of a construction kit starts to shine.
In our case, instead of implementing ISet<T> interface directly, we just derive our implementation from the one provided by the corresponding construction kit:
using Gapotchenko.FX.Collections.Generic.Kits;
using Gapotchenko.FX.Linq;
using System.Collections;
class MyBitSet(int capacity) : SetKit<int>
{
public override bool Contains(int item) => m_Bits[item];
public override bool Add(int item) => ChangeBit(item, true);
public override bool Remove(int item) => ChangeBit(item, false);
bool ChangeBit(int item, bool value)
{
if (m_Bits[item] != value)
{
m_Bits[item] = value;
if (value)
++m_CachedCount;
else
--m_CachedCount;
return true;
}
else
{
return false;
}
}
public override void Clear()
{
m_Bits.SetAll(false);
m_CachedCount = 0;
}
public override int Count => m_CachedCount ??= this.Stream().Count();
int? m_CachedCount = 0;
public override IEnumerator<int> GetEnumerator()
{
for (int i = 0, n = m_Bits.Count; i < n; ++i)
if (m_Bits[i])
yield return i;
}
protected BitArray Bits
{
get => m_Bits;
set { m_Bits = value; m_CachedCount = null; }
}
BitArray m_Bits = new(capacity);
}
We implemented just several abstract methods and got a fully functional and compliant ISet<T> collection.
All the remaining implementation details are covered by the construction kit our class is derived from.
Mind you, a generic implementation does not mean inefficient. If we have a more optimized way to do some operations, we just override the corresponding methods:
class MyHWAcceleratedBitSet(int capacity) : MyBitSet(capacity)
{
public override bool Overlaps(IEnumerable<int> other)
{
if (other is MyBitSet bitSet)
return Bits.And(bitSet.Bits).HasAnySet();
else
return base.Overlaps(other);
}
public override void IntersectWith(IEnumerable<int> other)
{
if (other is MyBitSet bitSet)
Bits = Bits.And(bitSet.Bits);
else
base.IntersectWith(other);
}
public override void UnionWith(IEnumerable<int> other)
{
if (other is MyBitSet bitSet)
Bits = Bits.Or(bitSet.Bits);
else
base.UnionWith(other);
}
public override void ExceptWith(IEnumerable<int> other)
{
if (other is MyBitSet bitSet)
Bits = Bits.And(bitSet.Bits.Not());
else
base.ExceptWith(other);
}
public override void SymmetricExceptWith(IEnumerable<int> other)
{
if (other is MyBitSet bitSet)
Bits = Bits.Xor(bitSet.Bits);
else
base.SymmetricExceptWith(other);
}
public override bool SetEquals(IEnumerable<int> other)
{
if (other is MyBitSet bitSet)
return bitSet.Bits.Xor(bitSet.Bits).HasAnySet();
else
return base.SetEquals(other);
}
}
Given that BitArray operations are hardware-accelerated in all modern .NET versions,
it quickly boils from a generic ISet<T> implementation down to a highly-optimized one, leveraging AVX and SSE vector instructions provided by CPU.
What a ride just within a screen of code.
</details>
AddRange is a frequently used operation that allows you to add a sequence of elements to the end of a collection.
Like this:
using Gapotchenko.FX.Collections.Generic;
var collection = new Collection<int>();
…
collection.AddRange(numbers.Where(x => x % 2 == 0)); // add even numbers
PriorityQueue<TElement, TPriority> provided by Gapotchenko.FX.Collections module is an implementation of the prioritized queue available since .NET 6.0.
The polyfill makes it available to all other supported .NET versions.
<details> <summary>Other polyfills</summary>
.NET provides a versatile KeyValuePair<TKey, TValue> struct and suggests a default way for its instantiation:
new KeyValuePair<TKey, TValue>(key, value)
Which is, well, not handy as it often comes to this:
new KeyValuePair<BindingManagerDataErrorEventHandler, ICom2PropertyPageDisplayService>(key, value)
Gapotchenko.FX.Collections provides a better way to instantiate a KeyValuePair<TKey, TValue> struct:
using Gapotchenko.FX.Collections.Generic;
KeyValuePair.Create(key, value)
It leverages the automatic type inference provided by some .NET languages like C#.
Gapotchenko.FX.Collections module comes with a function for KeyValuePair<TKey, TValue> deconstruction, so you can write this:
using Gapotchenko.FX.Collections.Generic;
void ProcessMap(IDictionary<string, int> map)
{
foreach (var (key, value) in map)
{
…
}
}
instead of a more verbose variant:
void ProcessMap(IDictionary<string, int> map)
{
foreach (var i in map)
{
var key = i.Key;
var value = i.Value;
…
}
}
A little detail, but sometimes it matters a lot when you are amid the heat of the code.
</details>
Gapotchenko.FX.Collections.Concurrent.ConcurrentHashSet<T>Gapotchenko.FX.Collections.Generic.AssociativeArray<T>Let's continue with a look at some other modules provided by Gapotchenko.FX:
Or look at the full list of modules.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 is compatible. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Gapotchenko.FX.Collections:
| Package | Downloads |
|---|---|
|
Gapotchenko.FX.Threading
Provides complementary primitives for multithreaded and asynchronous programming in .NET. |
|
|
Gapotchenko.FX.Profiles.Core
Represents the Core profile of Gapotchenko.FX toolkit. |
|
|
Gapotchenko.FX.Math.Combinatorics
Provides math operations for combinatorics. |
|
|
Gapotchenko.FX.IO.Vfs
Provides a virtual file system (VFS) abstraction layer that enables uniform access to different file storage backends, including local file systems, archives, and custom storage formats. |
|
|
Gapotchenko.FX.Math.Metrics
Provides math metrics algorithms. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.7.2 | 4,523 | 5/16/2026 |
| 2026.6.2 | 5,979 | 3/29/2026 |
| 2026.5.3 | 1,777 | 2/24/2026 |
| 2026.4.2 | 827 | 2/4/2026 |
| 2026.3.5 | 763 | 1/29/2026 |
| 2026.2.2 | 4,031 | 1/25/2026 |
| 2026.1.5 | 724 | 1/13/2026 |
| 2025.1.45 | 2,591 | 12/25/2025 |
| 2025.1.27-beta | 711 | 10/8/2025 |
| 2025.1.26-beta | 719 | 8/30/2025 |
| 2025.1.25-beta | 1,405 | 7/22/2025 |
| 2025.1.24-beta | 883 | 7/16/2025 |
| 2025.1.23-beta | 725 | 7/12/2025 |
| 2024.2.5 | 23,556 | 12/31/2024 |
| 2024.1.3 | 5,016 | 11/10/2024 |
| 2022.2.7 | 2,083 | 5/1/2022 |
| 2022.2.5 | 1,764 | 5/1/2022 |
| 2022.1.4 | 1,768 | 4/6/2022 |
| 2021.2.21 | 1,887 | 1/21/2022 |