.Net IntervalUtility

.Net Interval Utility Demo Blazor WebAssembly

Examples

Equals of intervals

1)
var intervalA = new Interval<int>(3, 6);
var intervalB = new Interval<int>(4, 8);

var isEquals = intervalA == intervalB;
// => false


3 6
|--------------|
4 8
|-------------------|

2)
var intervalA = new Interval<int>(null, 4);
var intervalB = new Interval<int>(null, 4);

var isEquals = intervalA == intervalB;
// => true


4
--------------------|
4
--------------------|

Whether the value is included in an interval (by default, ends are not included) — InRange

1)
var interval = new Interval<int>(3, 6);

var intervalUtil = new IntervalUtil();
var isInRange = intervalUtil.InRange(interval, 4);
// => true


3 6
|--------------|
4
|
2)
var interval = new Interval<int>(null, 6);

var intervalUtil = new IntervalUtil();
var isInRange = intervalUtil.InRange(interval, 6, includeEnds:true);
// => true


6
------------------------------|
6
|

Exclude from intervalA intervalb — Exclude

1)
var intervalA = new Interval<int>(3, 6);
var intervalB = new Interval<int>(1, 4);

var intervalUtil = new IntervalUtil();
var res = intervalUtil.Exclude(intervalA, intervalB);
// => [4,6]


3 6
|--------------|
1 4
|--------------|
Result
4 6
|---------|
2)
var intervalA = new Interval<int>(3, null);
var intervalB = new Interval<int>(4, 5);

var intervalUtil = new IntervalUtil();
var res = intervalUtil.Exclude(intervalA, intervalB)
// => [3,4], [5,null]


3
|----------------------------------
4 5
|----|
Result
3 4 5
|----| |------------------------

Exclude from array intervalsA array intervalsB — Exclude

var intervalsA = new[] { new Interval<int>(1, 5), new Interval<int>(7, 10) };
var intervalsB =
new[] { new Interval<int>(0, 2), new Interval<int>(3, 5), new Interval<int>(8, 9) };

var intervalUtil = new IntervalUtil();
var res = intervalUtil.Exclude(intervalsA, intervalsB);
// => [2,3], [7,8], [9,10]


1 5 7 10
|-------------------| |--------------|
0 2 3 5 8 9
|---------| |---------| |----|
Result
2 3 7 8 9 10
|----| |----| |----|

Find intersections — Intersection

var intervalA = new Interval<int>(0, 3);
var intervalB = new Interval<int>(2, 4);

var intervalUtil = new IntervalUtil();
var res = intervalUtil.Intersection(intervalA, intervalB);
// => [2,3]


0 3
|--------------|
2 4
|---------|
Result
2 3
|----|
var arrayOfArrays = new[] {
new[] { new Interval<int>(2,5), new Interval<int>(7, 9) },
new[] { new Interval<int>(0,3), new Interval<int>(4, 6), new Interval<int>(7, 10) },
new[] { new Interval<int>(1,4), new Interval<int>(5, 8) },
};

var intervalUtil = new IntervalUtil();
var res = intervalUtil.Intersections(arrayOfArrays);
// => [2,3], [7,8]


2 5 7 9
|--------------| |---------|
0 3 4 6 7 10
|--------------| |---------| |--------------|
1 4 5 8
|--------------| |--------------|
Result
2 3 7 8
|----| |----|

--

--

--

https://boyko.tech/ , https://github.com/AlexeyBoiko , https://linkedin.com/in/alexey-boyko-tech

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Best Developer of WordPress: What Does It Take to Become a WordPress Developer? (In 6 Steps)

©『▷Sledujte』 Rytmus: Tempos DVDRip (2020) Filmy CZ-SK Online Videa a Zdarma Dabing HD

What is SFTP/FTP

You can build it. We can help you. www.grandhomedesign.com

NPM dependency hell: comparison with Symfony, Laravel and API Platform

How to Format Strings in Python

Making It Stick — A Developers’ Implementation Plan

What’s new C#

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alexey Boyko

Alexey Boyko

https://boyko.tech/ , https://github.com/AlexeyBoiko , https://linkedin.com/in/alexey-boyko-tech

More from Medium

How To: Breaking ASP.NET Core with Angular Project into Frontend and Backend

Wpf.Extensions.Hosting for running WPF on Generic Hosts has been released.

ASP.NET Core 6 Application with Feature Flags

Uploading files with ASP.NET Minimal APIs