If you restrict data to non-overlapping segments, you can use the functions of the binary tree <search.h> tsearch / tfind , etc., as a result of which you use whole interval tuples as keys. The supplied comparison function could easily put the general order into segments. To find a segment that contains a given point, tfind for a synthetic interval of width 0.
source share