Gapotchenko.FX.Collections 2022.2.7 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved

.NET 5.0 .NET Core 2.0 .NET Standard 2.0 .NET Framework 4.6
Install-Package Gapotchenko.FX.Collections -Version 2022.2.7
dotnet add package Gapotchenko.FX.Collections --version 2022.2.7
<PackageReference Include="Gapotchenko.FX.Collections" Version="2022.2.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gapotchenko.FX.Collections --version 2022.2.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Gapotchenko.FX.Collections, 2022.2.7"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Gapotchenko.FX.Collections as a Cake Addin
#addin nuget:?package=Gapotchenko.FX.Collections&version=2022.2.7

// Install Gapotchenko.FX.Collections as a Cake Tool
#tool nuget:?package=Gapotchenko.FX.Collections&version=2022.2.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Overview

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>

ConcurrentHashSet<T> provided by Gapotchenko.FX.Collections is a thread-safe implementation of HashSet<T>.

AssociativeArray<TKey, TValue>

AssociativeArray<TKey, TValue> provided by Gapotchenko.FX.Collections is a drop-in replacement for Dictionary<TKey, TValue> that can handle null keys.

In contrast, stock Dictionary<TKey, TValue> cannot work with null keys and throws an exception whenever a null key is encountered. Due to such an artificial narrowing of the key space, it becomes hardly possible to solve some kinds of tasks with Dictionary<TKey, TValue>.

AssociativeArray<TKey, TValue> resolves that by supporting a full space of keys without opinionated exclusions.

AddRange<T>(IEnumerable<T>) for Collections

AddRange is a highly demanded operation that allows 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

IsNullOrEmpty() for Containers

System.String class provides a convenient IsNullOrEmpty primitive.

Gapotchenko.FX.Collections extends availability of that primitive by providing IsNullOrEmpty() extension method for other container types. Here is an example:

using Gapotchenko.FX.Collections.Generic;

class Method
{
    List<Argument> m_Arguments;

    public bool HasArguments => !m_Arguments.IsNullOrEmpty();

    …
}

The use of an extension method for a null check may look controversial at first, but since the method starts with IsNull… prefix, it immediately communicates its purpose and function. Other benefits include automatic type inference and semantic locality.

Polyfills

KeyValuePair Polyfill

.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#.

PriorityQueue polyfill

PriorityQueue<TElement, TPriority> provided by Gapotchenko.FX.Collections module is an implementation of the prioritized queue introduced since .NET 6. The polyfill makes it available to all supported .NET versions.

Deconstruction

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.

Commonly Used Types

  • Gapotchenko.FX.Collections.Concurrent.ConcurrentHashSet
  • Gapotchenko.FX.Collections.Generic.AssociativeArray

Other Modules

Let's continue with a look at some other modules provided by Gapotchenko.FX:

Or look at the full list of modules.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Gapotchenko.FX.Collections:

Package Downloads
Gapotchenko.FX.Profiles.Core The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Represents the Core profile of Gapotchenko.FX.

Gapotchenko.FX.Math.Combinatorics The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

The module provides the math operations for combinatorics.

Gapotchenko.FX.Math.Geometry The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

The module provides primitives and operations for geometry math.

Gapotchenko.FX.Math.Topology The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

The module provides data structures and primitives for working with abstract topologies.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2022.2.7 99 5/1/2022
2022.2.5 72 5/1/2022
2022.1.4 106 4/6/2022
2021.2.21 132 1/21/2022
2021.2.20 113 1/17/2022
2021.1.5 340 7/6/2021
2020.2.2-beta 272 11/21/2020
2020.1.15 353 11/5/2020
2020.1.9-beta 270 7/14/2020
2020.1.8-beta 275 7/14/2020
2020.1.7-beta 300 7/14/2020
2020.1.1-beta 407 2/11/2020
2019.3.7 422 11/4/2019
2019.2.20 424 8/13/2019
2019.1.151 484 3/30/2019