ComparableIntervals 2.0.0

A library which helps doing common operations, such as union, intersection or complement, on intervals of IComparable types.

Install-Package ComparableIntervals -Version 2.0.0
dotnet add package ComparableIntervals --version 2.0.0
<PackageReference Include="ComparableIntervals" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ComparableIntervals --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

ComparableIntervals

A library which helps doing common operations, such as union, intersection or complement, on intervals of
IComparable types.

Disclaimer: I've created this library for a very specific application I'm developing in my company. I've tried to
make it more generic than I needed, but eventually it may be not as generic as it should be. If this library fits your
needs, you're welcome to use it, but if you need more functionalities, please don't ask for them. In any case, any
pull request is appreciated.

Getting started

Every method and class in this library is documented inline, but here are a few hints to get started.

Create two Intervals of type int:

var interval1 = Interval<int>.Closed(1, 5);
var interval2 = Interval<int>.Open(3, 7);

Perform some operations on them:

var intersection = interval1.Intersection(interval2); // => (3, 5]
var Union = interval1.Union(interval2); // => [1, 7)

Perform operations on lists of intervals:

var intervals1 = new List<Interval<int>> {
    Interval<int>.ClosedOpen(-2, 2),
    Interval<int>.OpenClosed(4, 8)
};
var intervals2 = new List<Interval<int>> {
    Interval<int>.Closed(0, 6),
};

var intersection = Intervals.Intersection(intervals1, intervals2); // => [0, 2), (4, 6]
var union = Intervals.Union(intervals1, intervals2); // => [-2, 8]
var complement = Intervals.Complement(intervals1); // => (-∞, -2), [2, 4], (8, ∞)

Library structure

This library library exposes a few objects to build and compute intervals.

struct Bound&lt;T&gt;: represents a bound of type T, where T : IComparable.
A bound may be open, closed, or may represent negative or positive infinity. Methods to create those types of bounds
are provided.

class Interval&lt;T&gt;: represents an interval of type T, where T : IComparable.
An interval is an entity with an upper bound and a lower bound. To create a closed, open, open-close, closed-open
interval, one of the provided methods may be used, otherwise it can be created providing its bounds.
Operations on an interval (such as union and intersection) are provided as extension methods, so that they can be
called on an instance of an interval or in a static way.

static class Intervals: a class which provides static methods to operate on collections of intervals.

ComparableIntervals

A library which helps doing common operations, such as union, intersection or complement, on intervals of
IComparable types.

Disclaimer: I've created this library for a very specific application I'm developing in my company. I've tried to
make it more generic than I needed, but eventually it may be not as generic as it should be. If this library fits your
needs, you're welcome to use it, but if you need more functionalities, please don't ask for them. In any case, any
pull request is appreciated.

Getting started

Every method and class in this library is documented inline, but here are a few hints to get started.

Create two Intervals of type int:

var interval1 = Interval<int>.Closed(1, 5);
var interval2 = Interval<int>.Open(3, 7);

Perform some operations on them:

var intersection = interval1.Intersection(interval2); // => (3, 5]
var Union = interval1.Union(interval2); // => [1, 7)

Perform operations on lists of intervals:

var intervals1 = new List<Interval<int>> {
    Interval<int>.ClosedOpen(-2, 2),
    Interval<int>.OpenClosed(4, 8)
};
var intervals2 = new List<Interval<int>> {
    Interval<int>.Closed(0, 6),
};

var intersection = Intervals.Intersection(intervals1, intervals2); // => [0, 2), (4, 6]
var union = Intervals.Union(intervals1, intervals2); // => [-2, 8]
var complement = Intervals.Complement(intervals1); // => (-∞, -2), [2, 4], (8, ∞)

Library structure

This library library exposes a few objects to build and compute intervals.

struct Bound&lt;T&gt;: represents a bound of type T, where T : IComparable.
A bound may be open, closed, or may represent negative or positive infinity. Methods to create those types of bounds
are provided.

class Interval&lt;T&gt;: represents an interval of type T, where T : IComparable.
An interval is an entity with an upper bound and a lower bound. To create a closed, open, open-close, closed-open
interval, one of the provided methods may be used, otherwise it can be created providing its bounds.
Operations on an interval (such as union and intersection) are provided as extension methods, so that they can be
called on an instance of an interval or in a static way.

static class Intervals: a class which provides static methods to operate on collections of intervals.

  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETFramework 4.5.1

    • No dependencies.
  • .NETFramework 4.5.2

    • No dependencies.
  • .NETFramework 4.6

    • No dependencies.
  • .NETFramework 4.6.1

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .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 History

Version Downloads Last updated
2.0.0 80 9/16/2020