RangeSet 0.1.2
See the version list below for details.
dotnet add package RangeSet --version 0.1.2
NuGet\Install-Package RangeSet -Version 0.1.2
<PackageReference Include="RangeSet" Version="0.1.2" />
<PackageVersion Include="RangeSet" Version="0.1.2" />
<PackageReference Include="RangeSet" />
paket add RangeSet --version 0.1.2
#r "nuget: RangeSet, 0.1.2"
#:package RangeSet@0.1.2
#addin nuget:?package=RangeSet&version=0.1.2
#tool nuget:?package=RangeSet&version=0.1.2
RangeSet
A high-performance, generic range set library for .NET with support for union, intersection, and difference operations. Works with any comparable type including integers, dates, and custom types.
Features
- Generic Design: Works with any type implementing
IComparable<T>,IEquatable<T>,IMinMaxValue<T>, and arithmetic operators - High Performance: Uses
Span<T>andref structfor zero-allocation operations - AOT Compatible: Fully compatible with .NET Native AOT compilation
- Type Safe: Compile-time type checking with no boxing for value types
- Set Operations: Union, Except (subtraction), and Intersect operations on range sets
Supported Types
- Numeric types:
uint,int,ulong,long, etc. - Date/Time:
DateTime,DateTimeOffset - Custom types implementing required interfaces
Installation
dotnet add package RangeSet
Quick Start
using RangeSet;
// Create ranges of unsigned integers
var range1 = new RangeArrayGeneric<uint>();
var range2 = new RangeArrayGeneric<uint>();
// Union two range sets
var union = range1.Union(range2, 1u);
// Subtract one range set from another
var difference = range1.Except(range2, 1u);
// Find intersection
var intersection = range1.Intersect(range2);
Core Types
RangeArrayGeneric<T>
The main range set struct that stores a normalized collection of non-overlapping, non-adjacent ranges.
public readonly ref struct RangeArrayGeneric<T>
where T : unmanaged, IEquatable<T>, IComparable<T>,
IMinMaxValue<T>, IAdditionOperators<T, T, T>,
ISubtractionOperators<T, T, T>
Operations:
Union()- Combine two range setsExcept()- Subtract one range set from anotherIntersect()- Find common ranges between two setsToArray()- Convert to array ofCustomRange<T>ToReadOnlySpan()- Access underlying span
CustomRange<T>
Represents a single inclusive range from First to Last.
public readonly struct CustomRange<T>
where T : struct, IEquatable<T>, IComparable<T>
Example:
var range = new CustomRange<uint>(1, 100);
Console.WriteLine(range); // "1 - 100"
SpanHelperGeneric
Low-level helper class for range operations on spans. Provides methods for:
UnionNormalizedNormalized()- Union of two normalized range setsExceptNormalizedSorted()- Difference between normalized and sorted rangesIntersectNormalizedNormalized()- Intersection of two normalized range setsMakeNormalizedFromUnsorted()- Normalize unsorted rangesSort()- Sort ranges by start value
Type Requirements
To use a custom type with RangeArrayGeneric<T>, it must implement:
public readonly struct MyType :
IEquatable<MyType>,
IComparable<MyType>,
IMinMaxValue<MyType>,
IAdditionOperators<MyType, MyType, MyType>,
ISubtractionOperators<MyType, MyType, MyType>
{
public static MyType MaxValue => ...;
public static MyType MinValue => ...;
// ... other interface implementations
}
Performance
The library is optimized for high-performance scenarios:
- Zero-allocation: Uses
Span<T>and stack allocation where possible - Normalized storage: Ranges are always stored sorted, non-overlapping, and non-adjacent
- Efficient algorithms: O(n) union, intersection, and difference operations
- AOT ready: No reflection or dynamic code generation
Benchmarks show excellent performance for range operations on large datasets.
Building
dotnet build --configuration Release
Testing
dotnet test
Benchmarks
Run benchmarks with:
dotnet run --project RangeSet.Benchmarks -c Release
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please ensure your code follows the existing patterns and passes all tests.
| 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
- CommunityToolkit.HighPerformance (>= 8.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.