Skip to content

konrazem/Sets-of-intervals-substraction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sets of intervals substraction

Method to get new list of free intervals from given lists of:

  • A: free intervals
  • B: taken/occupied intervals

New intervals is a set substraction of A / B that do not contain points that belongs to intervals in list B.

-------- TAKEN INTERVALS -----------
┌─────────┬───────┬─────┐
│ (index) │ start │ end │
├─────────┼───────┼─────┤
│    0    │  10   │ 12  │
│    1    │  15   │ 16  │
└─────────┴───────┴─────┘
-------- FREE INTERVALS -----------
┌─────────┬───────┬─────┐
│ (index) │ start │ end │
├─────────┼───────┼─────┤
│    0    │   8   │  9  │
│    1    │  11   │ 12  │
│    2    │  15   │ 17  │
└─────────┴───────┴─────┘
-------- NEW FREE INTERVALS -----------
┌─────────┬───────┬─────┐
│ (index) │ start │ end │
├─────────┼───────┼─────┤
│    0    │   8   │  9  │
│    1    │  16   │ 17  │
└─────────┴───────┴─────┘
--------- TEST 1 ----------
true

MOTIVATION

I cloudn't find efficient algorithm for getting substraction of sets of intervals.

Instead of looping and working on dynamic lists, project all intervals points on one timeline, sort and go point by point and set flags in order to collect free intervals.

About

Set substraction of 2 sets of intervals

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published