Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Library for creating and comparing intervals. Library support three types of boundaries: open, closed and infinity for both sides.

License

Notifications You must be signed in to change notification settings

RetailRocket/Interval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

.NET Core NuGet version

Interval

Generic library of types to describe interval of any points that can be compared to eachother. The library is as small as possible to be useful. I've created it to use in my own implimentation of Iterval Centered Tree. To do it I was need a couple of additional operation which I've implemented in external library of Interval Operations on purpose to keep this library clear.

Each boundary contains method CompareToPoint it allows to get position of point compare to boundary. For example point 0 with comparison to open lower bound of 0 will be less but for closed lower bound it will be equal. Infinity lower bound will be always less than any point but Infinity upper bound will be greater than any point.

Model

alternative text

Usage

Interval

Interval type is generic type and can have boundaries point of any type, but for comparison operation you will need to have comparer class for point type

var interval = new Interval<int>(
    lowerBound: ...,
    upperBound: ...
);

Interval Boundaries

Each of interval boundaries can be one of three possible types. It enable to have up to nine different intervals.

Closed Interval

Both boundaries points are inculded to theinterval

[a, b] = {x | a <= x <= b}

var closedInterval = new Interval<int>(
    lowerBound: new ClosedLowerBound<int>(0),
    upperBound: new ClosedUpperBound<int>(10));

Open Interval

Both boundaries points are not inculded to the interval

(a, b) = {x | a < x < b}

var openInterval = new Interval<int>(
    lowerBound: new OpenLowerBound<int>(0),
    upperBound: new OpenUpperBound<int>(10));

Infinity Interval

This interval include any point

(∞, ∞) = {x | ∞ < x < ∞}

var infinityInterval = new Interval<int>(
    lowerBound: new InfinityLowerBound<int>(),
    upperBound: new InfinityUpperBound<int>());

And you can combine bounds

Open Closed Interval

Lower boundary point is not included to the interval, upper bound is included to the interval

(a, b] = {x | a < x <= b}

var openClosedInterval = new Interval<int>(
    lowerBound: new OpenLowerBound<int>(0),
    upperBound: new ClosedUpperBound<int>(10));

Closed Open Interval

Lower boundary point is included to the interval, upper bound is not

[a, b) = {x | a <= x < b}

var closedOpenInterval = new Interval<int>(
    lowerBound: new ClosedLowerBound<int>(0),
    upperBound: new OpenUpperBound<int>(10));

Infinity Open Interval

Lower boundary is infinity and any point of the interval is more than it boundary, upper boundary point is not included to the interval

(∞, a) = {x | ∞ < x < b}

var infinityOpenInterval = new Interval<int>(
    lowerBound: new InfinityLowerBound<int>(),
    upperBound: new OpenUpperBound<int>(10));

Infinity Closed Interval

Lower boundary is infinity and any point of the interval is more than it boundary, upper boundary point is included to the interval

(∞, a) = {x | ∞ < x <= b}

var infinityClosedInterval = new Interval<int>(
    lowerBound: new InfinityLowerBound<int>(),
    upperBound: new ClosedUpperBound<int>(10));

Open Infinity Interval

Lower boundary point is not included to the interval, upper bound is infinity and any point of interval is less that it boundary

(a, ∞) = {x | a < x < ∞}

var openInfinityInterval = new Interval<int>(
    lowerBound: new OpenLowerBound<int>(0),
    upperBound: new InfinityUpperBound<int>(10));

Closed Infinity Interval

Lower boundary point is included to the interval, upper bound is infinity and any point of interval is less that it boundary

[a, ∞) = {x | a <= x < ∞}

var closedInfinityInterval = new Interval<int>(
    lowerBound: new ClosedLowerBound<int>(0),
    upperBound: new InfinityUpperBound<int>(10));

Boundary Operation

Every boundary can be compared to point by CompareToPoint method. Methor returns -1 boundary at the left, 1 if the boundary at the right and 0 if point on the boundary.

  new ClosedLowerBound<int>(10)
    .CompareToPoint(
        point: 10,
        comparer: Comparer<int>.Default); // == 0 - point is on the boundary

Every lower boundary can be compared to another lower boundary by Comapre method

  new ClosedLowerBound<int>(10)
    .Compare(
        another: new OpenLowerBound<int>(11),
        comparer: Comparer<int>.Default); // == 0 - point is on the boundary

And every upper boundary can be compared to another upper boundary by Comapre method

  new OpenUpperBound<int>(10)
    .Compare(
        another: new ClosedUpperBound<int>(11),
        comparer: Comparer<int>.Default); // == 0 - point is on the boundary

Interval Operation

About

Library for creating and comparing intervals. Library support three types of boundaries: open, closed and infinity for both sides.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages