In your case, all the intervals are disjoint, a simple binary earch mechanism is enough to solve this issue (i.e. just check the even/odd of array index) For overlapping ones, the best solution is the interval tree. Some other algorithms that have slightly longer constant are R tree, or search trees built on top of GiST (which would be a nice index scheme for database).
【在 c*****t 的大作中提到】 : In your case, all the intervals are disjoint, a simple binary earch : mechanism is enough to solve this issue (i.e. just check the even/odd : of array index) : For overlapping ones, the best solution is the interval tree. : Some other algorithms that have slightly longer constant are R : tree, or search trees built on top of GiST (which would be a nice : index scheme for database).