SparseBitsets 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SparseBitsets --version 1.0.0                
NuGet\Install-Package SparseBitsets -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SparseBitsets" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SparseBitsets --version 1.0.0                
#r "nuget: SparseBitsets, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SparseBitsets as a Cake Addin
#addin nuget:?package=SparseBitsets&version=1.0.0

// Install SparseBitsets as a Cake Tool
#tool nuget:?package=SparseBitsets&version=1.0.0                

Sparse Bitsets

A pure C# implementation of sparse bitsets.

Sparse bitsets are a way of storing unique integer values in very little space. Using the SparseBitset you can store integer values of up to 64-bit unsigned.

You can then use boolean operator extension methods on two SparseBitsets to filter or merge the bitsets. You can also get the count of bits in the bitset. This makes SparseBitsets a useful tool for filtering and analyzing data that can be assigned into unique ids.

For example, you have a large dataset of people who like ice cream and another large set of people who play video games. If each person has an ID, you can create two SparseBitsets, each containing the IDs of the groups of people and using the boolean operators, find out very efficiently those people who both like ice cream and also play video games.

In many cases this can be faster and more performant than SQL. It's also possible to serialize the Bitsets so that they don't have to be created everytime.

Usage

SparseBitsets are initially stored in a temporary dictionary to speed up insertion. After adding the bits / values, call Pack() on the bitset to make the bitsets ready for processing.

    var bitset = new SparseBitset();

    for(int i = 1000; i < 2000; i++){
        bitset.Add(i);
    }

    for(int i = 1000000; i < 1002000; i++){
        bitset.Add(i);
    }

    for(int i = 6000000; i < 6002000; i++){
        bitset.Add(i);
    }

    bitset.Pack();

Once the bitsets are packed, you can use boolean operator extension methods for filtering, merging the bitsets.

    var bitset3 = bitset1.And(bitset2); // filters bitset1 by bitset 2
    var bitset4 = bitset1.Or(bitset2); // merges bitset1 with bitset 2

In order to perform a Not(), you must have the full bitset, or the complete set of unique ids.

    bitset1.Not(bitset2, fullBitset);

Use GetPopCount() to return the number of values stored in the bitset. For example, to find out the number of people who both liked ice clream and played video games:

    var bitset3 = bitset1.And(bitset2);
    bitset3.GetPopCount();

Use GetPopCount() to return the number of values stored in the bitset. For example, to find out the number of people who both liked ice clream and played video games:

    var bitset3 = bitset1.And(bitset2);
    bitset3.GetPopCount();

Use GetValues() to return the actual IDs or values stored in the bitset.

    var values = bitset3.GetValues();
    foreach(var value in values)
    {
        ///...     
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 348 12/24/2022
1.0.0 543 11/9/2020