Data structure for non-overlapping ranges within a single dimension

前端 未结 8 1412
再見小時候
再見小時候 2020-12-30 11:26

I need a data structure that can store non-overlapping ranges within a single dimension. The entire range of the dimension need not be completely covered.

An example

8条回答
  •  半阙折子戏
    2020-12-30 12:01

    The normalized way to represent your data would be to store a record for each unit of time. This can be done in the example of the conference scheduling application. Your constraint would be a unique constraint for

    (RoomId, StartTime)
    

    In the case of continuous ranges, you necessarily need to store 2 things, one boundary and either the second boundary or the length. It is usually done by storing the second boundary and then creating a constraint on both boundary of the kind

    (boundary not between colBoudaryA and colBoundaryB)
    

    with the additional constraint that

    (startBoundary < endBoundary)
    

提交回复
热议问题