Data structure for quick time interval look up

后端 未结 4 1542
一整个雨季
一整个雨季 2020-12-02 17:31

I have a set of time intervals In = (an, bn). I need to run lots of look ups where I\'m given a time t and need to quickly return the intervals that conta

4条回答
  •  猫巷女王i
    2020-12-02 18:10

    What you are looking for is an Interval Tree (which is a type of Range Tree).

    These have logarithmic lookup time like other tree structures (e.g., RB trees), so you should see comparable performance to using something like a Java TreeMap or an STL map.

    • Code for Red-black trees and interval trees from MIT
    • There is a C++ implementation in the CGAL Library.
    • Here's a C# Implementation

提交回复
热议问题