There are some sequences like:
op_num: [start, end], type
1: [0, 10], Wrtie // op_1 will write the range [0,10]
2: [5, 10], Read // op_2 will read the range [9,10]
3: [6, 7], Read
4: [6, 7], Write
Now I am going to write an algorithm to get the dependencies of them.
For op_2
, since [9,10]
is just wrote by op_1
, so op_2
has to wait for op_1
finishing.
For op_3
, althouth [6,7]
is also just read by op_2
,but since read op does not have to wait read op, op_3
only need to wait for op_1
.
For op_4
, [6,7]
is read by 'op_2 and 'op_3
, and is wrote by op_1
, but since op_2
and op_3
would wait for op_1
, so op_4
only need to wait for op_2
and op_3
explicitly.
The final goal is to generate the waiting sequences, like:
2 --> 1
3 --> 1
4 --> 2
4 --> 3
I'm trying to find an algorithm as fast as possible. I think maybe segment tree could help? But I'm not able to firgure it out.