I have a time interval like this:
[5,10]
and I have more list of time point, with different length, for example:
t1=[3,6,9,10]
t2=[2,4,5,6,10]
..
where in t1 [3,6]
is the first interval, [6,9]
the second and so on.
Same thing for t2
and other list.
Now I need to save the list, and the specific interval, that intersect with first time interval. For example in t1
I have [3,6]
that intersect on [5,10], [6,9]
that intersect with [5,10]
, etc.
I have made an algorithm but I work with more data and I need a fast algorithm. For example if I work with 300.000 list and every list have 200 time points my algorithm 1 fine in about 5-10sec. But if I have 10.000 or more time point the algorithm is very slow.
My algorithm is like this:
First time interval <- [t1,t2]
For each list
For each time interval [s1,s2] in list
if(s1>= t1 && s2 <= t2)
{
saveIntervall()
}
else if (s1<= t2 && s2 > t2)
{
saveIntervall()
}
else if(s1 < t1 && s2 >= t1)
{
saveIntervall()
}
else if (s1 < t1 && s2 > t2)
{
saveIntervall()
}
Edit1: Yes I have ordered list.
Edit2: I have another problem, when i find the intersaction i need to calclulate a score between 0 and 1 of how the intersection is large. I use this:
double score = 0.0d;
if(s1>= t1 && s2 <= t2)
{
score = (s2-s1) / (t2-t1);
}
else if(t2 >= s2 && t1 > s1)
{
score = (s2-t1) / (t2-t1);
}
else if(t2 < s2 && t1 <= s1)
{
score = (t2-s1) / (t2-t1);
}
else
{
score = 1;
}
I can speed up this too?