Data structure for non-overlapping ranges within a single dimension

前端 未结 8 1370
再見小時候
再見小時候 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:06

    I've had success storing a beginning time and duration. The test for overlap would be something like

    WHERE NOT EXISTS (
       SELECT 1 FROM table
       WHERE BeginTime < NewBeginTime AND BeginTime + Duration > NewBeginTime
    )
    AND NOT EXISTS (
       SELECT 1 FROM table
       WHERE NewBeginTime < BeginTime AND NewBeginTime + NewDuration > BeginTime
    )
    

    I think without testing, but hopefully you get the drift

提交回复
热议问题